Skip to content

Commit

Permalink
repository: set target to spec.TargetDir if set (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvisa authored Sep 28, 2020
1 parent 879ae13 commit da151c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,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, "/tmp/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: "/tmp/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, "/tmp/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 "/tmp/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 da151c5

Please sign in to comment.