Skip to content

Commit

Permalink
Merge pull request #496 from oldthreefeng/fix491
Browse files Browse the repository at this point in the history
validate copy kubetarball
  • Loading branch information
fanux authored Oct 15, 2020
2 parents a76ade0 + c87742d commit ac1f735
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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)
_ = 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)
}

0 comments on commit ac1f735

Please sign in to comment.