Skip to content

Commit

Permalink
fix: scp files (#4041) (#4042)
Browse files Browse the repository at this point in the history
* fix: scp files

* fix: scp files

* fix: scp files

* fix: scp files

Co-authored-by: 榴莲榴莲 <78798447@qq.com>
  • Loading branch information
2 people authored and sealos-ci-robot@sealos.io committed Oct 8, 2023
1 parent 7ad66b4 commit 240e55b
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pkg/ssh/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,27 @@ func (c *Client) doCopy(client *sftp.Client, host, src, dest string, epu *progre
}
defer lf.Close()

dstfp, err := client.Create(dest)
if err != nil {
return fmt.Errorf("failed to create: %v", err)
}
if err = dstfp.Chmod(lfp.Mode()); err != nil {
return fmt.Errorf("failed to Chmod dst: %v", err)
destTmp := dest + ".tmp"
if err = func(tmpName string) error {
dstfp, err := client.Create(tmpName)
if err != nil {
return fmt.Errorf("failed to create: %v", err)
}
defer dstfp.Close()

if err = dstfp.Chmod(lfp.Mode()); err != nil {
return fmt.Errorf("failed to Chmod dst: %v", err)
}
if _, err = io.Copy(dstfp, lf); err != nil {
return fmt.Errorf("failed to Copy: %v", err)
}
return nil
}(destTmp); err != nil {
return err
}
defer dstfp.Close()
if _, err = io.Copy(dstfp, lf); err != nil {
return fmt.Errorf("failed to Copy: %v", err)

if err = client.PosixRename(destTmp, dest); err != nil {
return fmt.Errorf("failed to rename %s to %s: %v", destTmp, dest, err)
}
if isCheckFileMD5() {
dh := c.RemoteSha256Sum(host, dest)
Expand Down

0 comments on commit 240e55b

Please sign in to comment.