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

validate copy kubetarball #496

Merged
merged 1 commit into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion install/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ func SendPackage(location string, hosts []string, dst string, before, after *str
_ = SSHConfig.CmdAsync(host, *before)
}
if SSHConfig.IsFileExist(host, fullPath) {
logger.Warn("[%s]SendPackage: file is exist", host)
if SSHConfig.ValidateMd5sumLocalWithRemote(host, location, fullPath) {
logger.Info("[%s]SendPackage: %s file is exist and ValidateMd5 success", host, fullPath)
} else {
rm := fmt.Sprintf("rm -f %s", fullPath)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这里待考虑, 复制过程, 文件存在 ,但是目标文件的md5和源文件的md5校验失败的情况下. sealos该如何处理??

_ = SSHConfig.Cmd(host, rm)
// del then copy
if ok := SSHConfig.CopyForMD5(host, location, fullPath, md5); ok {
logger.Info("[%s]copy file md5 validate success", host)
} else {
logger.Error("[%s]copy file md5 validate failed", host)
}
}
} else {
if ok := SSHConfig.CopyForMD5(host, location, fullPath, md5); ok {
logger.Info("[%s]copy file md5 validate success", host)
Expand Down
5 changes: 5 additions & 0 deletions pkg/sshcmd/sshutil/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,8 @@ func (ss *SSH) isCopyMd5Success(sshClient *ssh.Client, localFile, remoteFile str
}
return localMd5 == remoteMd5
}

func (ss *SSH) ValidateMd5sumLocalWithRemote(host, localFile, remoteFile string) bool {
localMd5 := md5sum.FromLocal(localFile)
return localMd5 == ss.Md5Sum(host, remoteFile)
}