2023-03-10 20:27:30 +02:00
|
|
|
package fingerprint
|
2017-09-16 16:44:13 +02:00
|
|
|
|
|
|
|
import (
|
2019-08-21 06:33:12 +02:00
|
|
|
"os"
|
2017-09-16 16:44:13 +02:00
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/mattn/go-zglob"
|
2021-01-07 16:48:33 +02:00
|
|
|
|
|
|
|
"github.com/go-task/task/v3/internal/execext"
|
2022-08-06 23:19:07 +02:00
|
|
|
"github.com/go-task/task/v3/internal/filepathext"
|
2017-09-16 16:44:13 +02:00
|
|
|
)
|
|
|
|
|
2019-08-25 21:29:32 +02:00
|
|
|
func globs(dir string, globs []string) ([]string, error) {
|
2019-08-21 06:33:12 +02:00
|
|
|
files := make([]string, 0)
|
2017-09-16 16:44:13 +02:00
|
|
|
for _, g := range globs {
|
2021-05-08 22:02:08 +02:00
|
|
|
f, err := Glob(dir, g)
|
2017-11-02 14:25:50 +02:00
|
|
|
if err != nil {
|
2019-08-21 06:33:12 +02:00
|
|
|
continue
|
2017-11-02 14:25:50 +02:00
|
|
|
}
|
2019-08-21 06:33:12 +02:00
|
|
|
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) {
|
2019-08-21 06:33:12 +02:00
|
|
|
files := make([]string, 0)
|
2022-08-06 23:19:07 +02:00
|
|
|
g = filepathext.SmartJoin(dir, g)
|
|
|
|
|
2019-08-21 06:33:12 +02:00
|
|
|
g, err := execext.Expand(g)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-06 23:19:07 +02:00
|
|
|
|
2022-08-23 18:25:11 +02:00
|
|
|
fs, err := zglob.GlobFollowSymlinks(g)
|
2019-08-21 06:33:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-06 23:19:07 +02:00
|
|
|
|
2019-08-21 06:33:12 +02:00
|
|
|
for _, f := range fs {
|
|
|
|
info, err := os.Stat(f)
|
2017-09-16 16:44:13 +02:00
|
|
|
if err != nil {
|
2019-08-25 21:29:32 +02:00
|
|
|
return nil, err
|
2017-09-16 16:44:13 +02:00
|
|
|
}
|
2019-08-21 06:33:12 +02:00
|
|
|
if info.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
files = append(files, f)
|
2017-09-16 16:44:13 +02:00
|
|
|
}
|
2019-08-21 06:33:12 +02:00
|
|
|
return files, nil
|
2017-09-16 16:44:13 +02:00
|
|
|
}
|