Skip to content

Commit

Permalink
Simplify command to get size and modtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Nov 11, 2019
1 parent 006b802 commit e9d2126
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
7 changes: 2 additions & 5 deletions pkg/minikube/assets/vm_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (b *BaseAsset) GetPermissions() string {

// GetModTime returns mod time
func (b *BaseAsset) GetModTime() (time.Time, error) {
return time.Time{}, errors.New("modtime isn't available for this asset")
return time.Time{}, nil
}

// FileAsset is an asset using a file
Expand Down Expand Up @@ -114,10 +114,7 @@ func (f *FileAsset) GetLength() (flen int) {
// GetModTime returns modification time of the file
func (f *FileAsset) GetModTime() (time.Time, error) {
fi, err := os.Stat(f.AssetName)
if err != nil {
return time.Time{}, err
}
return fi.ModTime(), nil
return fi.ModTime(), err
}

func (f *FileAsset) Read(p []byte) (int, error) {
Expand Down
17 changes: 9 additions & 8 deletions pkg/minikube/command/ssh_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ func (s *SSHRunner) Copy(f assets.CopyableFile) error {
dst := path.Join(path.Join(f.GetTargetDir(), f.GetTargetName()))
exists, err := s.sameFileExists(f, dst)
if err != nil {
glog.Infof("Checked if %s exists, but got error: %v", f.GetAssetName(), err)
glog.Infof("Checked if %s exists, but got error: %v", dst, err)
}
if exists {
glog.Infof("Skipping copying %s as it already exists", f.GetAssetName())
glog.Infof("Skipping copying %s as it already exists", dst)
return nil
}
sess, err := s.c.NewSession()
Expand Down Expand Up @@ -198,7 +198,7 @@ func (s *SSHRunner) Copy(f assets.CopyableFile) error {
scp := fmt.Sprintf("sudo mkdir -p %s && sudo scp -t %s", f.GetTargetDir(), f.GetTargetDir())
mtime, err := f.GetModTime()
if err != nil {
glog.Infof("error getting modtime for %s: %v", f.GetAssetName(), err)
glog.Infof("error getting modtime for %s: %v", dst, err)
} else {
scp += fmt.Sprintf(" && sudo touch -d \"%s\" %s", mtime.Format(layout), dst)
}
Expand All @@ -216,21 +216,22 @@ func (s *SSHRunner) sameFileExists(f assets.CopyableFile, dst string) (bool, err
if err != nil {
return false, err
}
if srcModTime.IsZero() {
return false, nil
}

// get file size and modtime of the destination
sess, err := s.c.NewSession()
if err != nil {
return false, err
}

size := fmt.Sprintf("ls -l %s | cut -d \" \" -f5", dst)
stat := "stat -c %y" + fmt.Sprintf(" %s", dst)

out, err := sess.CombinedOutput(size + " && " + stat)
cmd := "stat -c \"%s %y\" " + dst
out, err := sess.CombinedOutput(cmd)
if err != nil {
return false, err
}
outputs := strings.Split(strings.Trim(string(out), "\n"), "\n")
outputs := strings.SplitN(strings.Trim(string(out), "\n"), " ", 2)

dstSize, err := strconv.Atoi(outputs[0])
if err != nil {
Expand Down

0 comments on commit e9d2126

Please sign in to comment.