1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00
task/file.go
2017-02-27 17:03:25 -03:00

88 lines
1.4 KiB
Go

package task
import (
"os"
"time"
"github.com/mattn/go-zglob"
)
var dirsToSkip = []string{
".git",
"node_modules",
}
func minTime(a, b time.Time) time.Time {
if !a.IsZero() && a.Before(b) {
return a
}
return b
}
func maxTime(a, b time.Time) time.Time {
if a.After(b) {
return a
}
return b
}
func getPatternsMinTime(patterns []string) (m time.Time, err error) {
for _, p := range patterns {
mp, err := getPatternMinTime(p)
if err != nil {
return time.Time{}, err
}
m = minTime(m, mp)
}
return
}
func getPatternsMaxTime(patterns []string) (m time.Time, err error) {
for _, p := range patterns {
mp, err := getPatternMaxTime(p)
if err != nil {
return time.Time{}, err
}
m = maxTime(m, mp)
}
return
}
func getPatternMinTime(pattern string) (minTime time.Time, err error) {
files, err := zglob.Glob(pattern)
if err != nil {
return time.Time{}, err
}
for _, f := range files {
info, err := os.Stat(f)
if err != nil {
return time.Time{}, err
}
modTime := info.ModTime()
if minTime.IsZero() || modTime.Before(minTime) {
minTime = modTime
}
}
return
}
func getPatternMaxTime(pattern string) (maxTime time.Time, err error) {
files, err := zglob.Glob(pattern)
if err != nil {
return time.Time{}, err
}
for _, f := range files {
info, err := os.Stat(f)
if err != nil {
return time.Time{}, err
}
modTime := info.ModTime()
if modTime.After(maxTime) {
maxTime = modTime
}
}
return
}