Don't copy unmodified files from source to dest

This commit is contained in:
Alex Yatskov 2016-01-12 17:04:41 +09:00
parent da057ec544
commit 31beb8b2c0
2 changed files with 18 additions and 0 deletions

View File

@ -39,6 +39,10 @@ type file struct {
} }
func (f *file) export(dstPath string) error { func (f *file) export(dstPath string) error {
if f.reader == nil && fileCached(f.asset, dstPath) {
return nil
}
if err := os.MkdirAll(path.Dir(dstPath), 0755); err != nil { if err := os.MkdirAll(path.Dir(dstPath), 0755); err != nil {
return err return err
} }

14
util.go
View File

@ -66,3 +66,17 @@ func scanDir(root string, files, dirs chan string) {
return nil return nil
}) })
} }
func fileCached(srcPath, dstPath string) bool {
srcStat, err := os.Stat(srcPath)
if err != nil {
return false
}
dstStat, err := os.Stat(dstPath)
if err != nil {
return false
}
return dstStat.ModTime().Unix() >= srcStat.ModTime().Unix()
}