提交 e9d21265 编写于 作者: P Priya Wadhwa

Simplify command to get size and modtime

上级 006b802e
......@@ -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
......@@ -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) {
......
......@@ -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()
......@@ -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)
}
......@@ -216,6 +216,9 @@ 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()
......@@ -223,14 +226,12 @@ func (s *SSHRunner) sameFileExists(f assets.CopyableFile, dst string) (bool, err
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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册