Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: scp files #4041

Merged
merged 4 commits into from
Oct 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions pkg/ssh/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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