1
0
mirror of https://github.com/go-task/task.git synced 2024-12-14 10:52:43 +02:00
task/internal/fingerprint/glob.go

52 lines
866 B
Go
Raw Normal View History

package fingerprint
import (
"os"
"sort"
"github.com/mattn/go-zglob"
"github.com/go-task/task/v3/internal/execext"
"github.com/go-task/task/v3/internal/filepathext"
)
2019-08-25 21:29:32 +02:00
func globs(dir string, globs []string) ([]string, error) {
files := make([]string, 0)
for _, g := range globs {
2021-05-08 22:02:08 +02:00
f, err := Glob(dir, g)
if err != nil {
continue
}
files = append(files, f...)
}
sort.Strings(files)
return files, nil
}
2021-05-08 22:02:08 +02:00
func Glob(dir string, g string) ([]string, error) {
files := make([]string, 0)
g = filepathext.SmartJoin(dir, g)
g, err := execext.Expand(g)
if err != nil {
return nil, err
}
fs, err := zglob.GlobFollowSymlinks(g)
if err != nil {
return nil, err
}
for _, f := range fs {
info, err := os.Stat(f)
if err != nil {
2019-08-25 21:29:32 +02:00
return nil, err
}
if info.IsDir() {
continue
}
files = append(files, f)
}
return files, nil
}