From a54105e07e2a3c51379ee2e11df78d0afb194a39 Mon Sep 17 00:00:00 2001 From: Wine93 Date: Mon, 17 Apr 2023 14:56:51 +0800 Subject: [PATCH] Fix(support): download file failed by ssh when remote path is same as local path. Signed-off-by: Wine93 --- internal/task/task/common/collect_service.go | 7 +++---- internal/utils/file.go | 2 ++ internal/utils/file_test.go | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 internal/utils/file_test.go diff --git a/internal/task/task/common/collect_service.go b/internal/task/task/common/collect_service.go index 75460d2ca..9718d38a6 100644 --- a/internal/task/task/common/collect_service.go +++ b/internal/task/task/common/collect_service.go @@ -97,15 +97,14 @@ func NewCollectServiceTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (* // add step to task var out string - //var files []string secret := curveadm.MemStorage().Get(comm.KEY_SECRET).(string) urlFormat := curveadm.MemStorage().Get(comm.KEY_SUPPORT_UPLOAD_URL_FORMAT).(string) baseDir := TEMP_DIR vname := utils.NewVariantName(fmt.Sprintf("%s_%s", serviceId, utils.RandString(5))) remoteSaveDir := fmt.Sprintf("%s/%s", baseDir, vname.Name) // /tmp/7b510fb63730_ox1fe remoteTarbllPath := path.Join(baseDir, vname.CompressName) // /tmp/7b510fb63730_ox1fe.tar.gz - localTarballPath := path.Join(baseDir, vname.CompressName) // /tmp/7b510fb63730_ox1fe.tar.gz - localEncryptdTarballPath := path.Join(baseDir, vname.EncryptCompressName) // // /tmp/7b510fb63730_ox1fe-encrypted.tar.gz + localTarballPath := path.Join(baseDir, vname.LocalCompressName) // /tmp/7b510fb63730_ox1fe.local.tar.gz + localEncryptdTarballPath := path.Join(baseDir, vname.EncryptCompressName) // /tmp/7b510fb63730_ox1fe-encrypted.tar.gz httpSavePath := path.Join("/", encodeSecret(secret), "service", dc.GetRole()) layout := dc.GetProjectLayout() containerLogDir := layout.ServiceLogDir // /curvebs/etcd/logs @@ -114,7 +113,7 @@ func NewCollectServiceTask(curveadm *cli.CurveAdm, dc *topology.DeployConfig) (* localOptions.ExecInLocal = true t.AddStep(&step.CreateDirectory{ - Paths: []string{remoteSaveDir /*, hostLogDir, hostConfDir*/}, + Paths: []string{remoteSaveDir}, ExecOptions: curveadm.ExecOptions(), }) t.AddStep(&step2CopyFilesFromContainer{ // copy logs directory diff --git a/internal/utils/file.go b/internal/utils/file.go index cca1bf602..0ecd12aa3 100644 --- a/internal/utils/file.go +++ b/internal/utils/file.go @@ -33,6 +33,7 @@ import ( type VariantName struct { Name string CompressName string + LocalCompressName string EncryptCompressName string } @@ -44,6 +45,7 @@ func NewVariantName(name string) VariantName { return VariantName{ Name: name, CompressName: fmt.Sprintf("%s.tar.gz", name), + LocalCompressName: fmt.Sprintf("%s.local.tar.gz", name), EncryptCompressName: fmt.Sprintf("%s-encrypted.tar.gz", name), } } diff --git a/internal/utils/file_test.go b/internal/utils/file_test.go new file mode 100644 index 000000000..108149afe --- /dev/null +++ b/internal/utils/file_test.go @@ -0,0 +1,16 @@ +package utils + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestVariantName(t *testing.T) { + assert := assert.New(t) + vname := NewVariantName("test") + assert.Equal("test", vname.Name) + assert.Equal("test.tar.gz", vname.CompressName) + assert.Equal("test.local.tar.gz", vname.LocalCompressName) + assert.Equal("test-encrypted.tar.gz", vname.EncryptCompressName) +}