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 { func (f *file) export(dstDir string) error {
dstPath := filepath.Join(dstDir, f.path) 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 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

View File

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

14
util.go
View File

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