Skip to content

Commit

Permalink
Fix(support): download file failed by ssh when remote path is same as…
Browse files Browse the repository at this point in the history
… local path.

Signed-off-by: Wine93 <[email protected]>
  • Loading branch information
Wine93 authored and caoxianfei1 committed Aug 7, 2023
1 parent 57fcce2 commit 3890e0b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/task/task/common/collect_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
type VariantName struct {
Name string
CompressName string
LocalCompressName string
EncryptCompressName string
}

Expand All @@ -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),
}
}
Expand Down
16 changes: 16 additions & 0 deletions internal/utils/file_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 3890e0b

Please sign in to comment.