From 570d2a0540cfa9b648c26cce8f924649376dfb9b Mon Sep 17 00:00:00 2001 From: 9547 Date: Sat, 26 Sep 2020 22:05:13 +0800 Subject: [PATCH] repository: set target to spec.TargetDir if set --- pkg/repository/v1_repository.go | 7 +++++-- pkg/repository/v1_repository_test.go | 5 ++++- pkg/repository/v1manifest/local_manifests.go | 12 +++++++----- tests/tiup/test_tiup.sh | 1 + 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/repository/v1_repository.go b/pkg/repository/v1_repository.go index d538b79de0..0aa2cde39a 100644 --- a/pkg/repository/v1_repository.go +++ b/pkg/repository/v1_repository.go @@ -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 { @@ -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) } diff --git a/pkg/repository/v1_repository_test.go b/pkg/repository/v1_repository_test.go index 020425f640..3e2abc5387 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, "/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: "/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{{ diff --git a/pkg/repository/v1manifest/local_manifests.go b/pkg/repository/v1manifest/local_manifests.go index bcc6907ad8..828a8c1c4d 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 "/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