Skip to content

Commit

Permalink
executor/ssh: adjust as per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis committed May 25, 2021
1 parent 8c27773 commit bb5d8ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion pkg/cluster/executor/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ var (
checkpoint.Field("src", reflect.DeepEqual),
checkpoint.Field("dst", reflect.DeepEqual),
checkpoint.Field("download", reflect.DeepEqual),
checkpoint.Field("limit", reflect.DeepEqual),
)
)

Expand Down
23 changes: 10 additions & 13 deletions pkg/cluster/executor/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ import (
// ScpDownload downloads a file from remote with SCP
// The implementation is partially inspired by github.com/dtylman/scp
func ScpDownload(session *ssh.Session, client *ssh.Client, src, dst string, limit int) error {
// prepare dst file
targetPath := filepath.Dir(dst)
if err := utils.CreateDir(targetPath); err != nil {
return err
}
targetFile, err := os.Create(dst)
if err != nil {
return err
}

r, err := session.StdoutPipe()
if err != nil {
return err
Expand All @@ -65,9 +55,17 @@ func ScpDownload(session *ssh.Session, client *ssh.Client, src, dst string, limi
if err != nil {
return fmt.Errorf("error parsing file mode; %s", err)
}
if err := targetFile.Chmod(fs.FileMode(mode)); err != nil {
return fmt.Errorf("error setting file mode; %s", err)

// prepare dst file
targetPath := filepath.Dir(dst)
if err := utils.CreateDir(targetPath); err != nil {
return err
}
targetFile, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE|os.O_TRUNC, fs.FileMode(mode))
if err != nil {
return err
}
defer targetFile.Close()

size, err := strconv.Atoi(strings.Fields(string(line))[1])
if err != nil {
Expand Down Expand Up @@ -96,7 +94,6 @@ func ScpDownload(session *ssh.Session, client *ssh.Client, src, dst string, limi
copyErrC := make(chan error, 1)
go func() {
defer w.Close()
defer targetFile.Close()
copyErrC <- copyF()
}()

Expand Down

0 comments on commit bb5d8ff

Please sign in to comment.