Skip to content

Commit

Permalink
repository: set target to spec.TargetDir if set
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvisa committed Sep 26, 2020
1 parent dfab8de commit 570d2a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
7 changes: 5 additions & 2 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ func (r *V1Repository) UpdateComponents(specs []ComponentSpec) error {
spec.Version = version
}

targetDir := filepath.Join(r.local.TargetRootDir(), localdata.ComponentParentDir, spec.ID, spec.Version)
targetDir := spec.TargetDir
if targetDir == "" {
targetDir = filepath.Join(r.local.TargetRootDir(), localdata.ComponentParentDir, spec.ID, spec.Version)
}
target := filepath.Join(targetDir, versionItem.URL)
err = r.DownloadComponent(versionItem, target)
if err != nil {
Expand All @@ -185,7 +188,7 @@ func (r *V1Repository) UpdateComponents(specs []ComponentSpec) error {
errs = append(errs, err.Error())
}

// remove the source gzip target if expand is on
// remove the source gzip target if expand is on && no keep source
if !r.DisableDecompress && !keepSource {
_ = os.Remove(target)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/repository/v1_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ func TestUpdateComponents(t *testing.T) {
assert.Equal(t, 1, len(local.Installed))
assert.Equal(t, "v2.0.1", local.Installed["foo"].Version)
assert.Equal(t, "foo201", local.Installed["foo"].Contents)
assert.Equal(t, "/mock/components/foo/v2.0.1/foo-2.0.1.tar.gz", local.Installed["foo"].BinaryPath)

// Update
foo.Version = 8
Expand All @@ -521,12 +522,14 @@ func TestUpdateComponents(t *testing.T) {
mirror.Resources[v1manifest.ManifestURLSnapshot] = snapStr
mirror.Resources[v1manifest.ManifestURLTimestamp] = serialize(t, ts, priv)
err = repo.UpdateComponents([]ComponentSpec{{
ID: "foo",
ID: "foo",
TargetDir: "/mock-mock",
}})
assert.Nil(t, err)
assert.Equal(t, 1, len(local.Installed))
assert.Equal(t, "v2.0.2", local.Installed["foo"].Version)
assert.Equal(t, "foo202", local.Installed["foo"].Contents)
assert.Equal(t, "/mock-mock/foo-2.0.2.tar.gz", local.Installed["foo"].BinaryPath)

// Update; already up to date
err = repo.UpdateComponents([]ComponentSpec{{
Expand Down
12 changes: 7 additions & 5 deletions pkg/repository/v1manifest/local_manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ type MockManifests struct {

// MockInstalled is used by MockManifests to remember what was installed for a component.
type MockInstalled struct {
Version string
Contents string
Version string
Contents string
BinaryPath string
}

// NewMockManifests creates an empty MockManifests.
Expand Down Expand Up @@ -384,8 +385,9 @@ func (ms *MockManifests) InstallComponent(reader io.Reader, targetDir string, co
return err
}
ms.Installed[component] = MockInstalled{
Version: version,
Contents: buf.String(),
Version: version,
Contents: buf.String(),
BinaryPath: filepath.Join(targetDir, filename),
}
return nil
}
Expand All @@ -397,7 +399,7 @@ func (ms *MockManifests) KeyStore() *KeyStore {

// TargetRootDir implements LocalManifests.
func (ms *MockManifests) TargetRootDir() string {
return ""
return "/mock"
}

// ManifestVersion implements LocalManifests.
Expand Down
1 change: 1 addition & 0 deletions tests/tiup/test_tiup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tiup
tiup help
tiup install tidb:v3.0.13
tiup update tidb
tiup update --self
tiup status
tiup clean --all
tiup help tidb
Expand Down

0 comments on commit 570d2a0

Please sign in to comment.