From 31beb8b2c02f03ba4b31d9e5696e575ce84f0d42 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 12 Jan 2016 17:04:41 +0900 Subject: [PATCH] Don't copy unmodified files from source to dest --- file.go | 4 ++++ util.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/file.go b/file.go index 719fd28..60c024b 100644 --- a/file.go +++ b/file.go @@ -39,6 +39,10 @@ type file struct { } 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 { return err } diff --git a/util.go b/util.go index 12cbd58..18a032d 100644 --- a/util.go +++ b/util.go @@ -66,3 +66,17 @@ func scanDir(root string, files, dirs chan string) { 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() +}