This commit is contained in:
Alex Yatskov 2016-06-11 19:38:17 -07:00
parent a7b084177e
commit 183c6e0066
3 changed files with 10 additions and 16 deletions

View File

@ -45,9 +45,12 @@ type file struct {
func (f *file) export(dstDir string) error {
dstPath := filepath.Join(dstDir, f.path)
if len(f.asset) > 0 && fileCached(f.asset, dstPath) {
if len(f.asset) > 0 {
dstInfo, err := os.Stat(dstPath)
if err == nil && dstInfo.ModTime().Unix() >= f.ModTime().Unix() {
return nil
}
}
if err := os.MkdirAll(path.Dir(dstPath), 0755); err != nil {
return err

View File

@ -24,6 +24,7 @@ package goldsmith
import (
"bytes"
"errors"
"io"
"os"
"time"
@ -73,6 +74,10 @@ func NewFileFromAsset(path, asset string) (File, error) {
return nil, err
}
if info.IsDir() {
return nil, errors.New("assets must be files")
}
f := &file{
path: path,
Meta: make(map[string]interface{}),

14
util.go
View File

@ -55,17 +55,3 @@ func scanDir(root string, infos chan fileInfo) {
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()
}