From da151c51c4ac847dd1d1289b933d394c26ed6f52 Mon Sep 17 00:00:00 2001 From: 9547 Date: Mon, 28 Sep 2020 16:51:11 +0800 Subject: [PATCH] repository: set target to spec.TargetDir if set (#820) --- pkg/repository/v1_repository.go | 2 +- pkg/repository/v1_repository_test.go | 5 ++++- pkg/repository/v1manifest/local_manifests.go | 12 +++++++----- tests/tiup/test_tiup.sh | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/repository/v1_repository.go b/pkg/repository/v1_repository.go index bb9ee71746..ca9494b39b 100644 --- a/pkg/repository/v1_repository.go +++ b/pkg/repository/v1_repository.go @@ -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) } diff --git a/pkg/repository/v1_repository_test.go b/pkg/repository/v1_repository_test.go index 020425f640..27faec8dfb 100644 --- a/pkg/repository/v1_repository_test.go +++ b/pkg/repository/v1_repository_test.go @@ -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 @@ -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{{ diff --git a/pkg/repository/v1manifest/local_manifests.go b/pkg/repository/v1manifest/local_manifests.go index bcc6907ad8..6bd913e82e 100644 --- a/pkg/repository/v1manifest/local_manifests.go +++ b/pkg/repository/v1manifest/local_manifests.go @@ -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. @@ -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 } @@ -397,7 +399,7 @@ func (ms *MockManifests) KeyStore() *KeyStore { // TargetRootDir implements LocalManifests. func (ms *MockManifests) TargetRootDir() string { - return "" + return "/tmp/mock" } // ManifestVersion implements LocalManifests. diff --git a/tests/tiup/test_tiup.sh b/tests/tiup/test_tiup.sh index 96bf5ce4ce..2a21df9e68 100755 --- a/tests/tiup/test_tiup.sh +++ b/tests/tiup/test_tiup.sh @@ -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