2017-09-16 16:44:13 +02:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
2019-08-21 06:33:12 +02:00
|
|
|
"os"
|
2017-09-16 16:44:13 +02:00
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/mattn/go-zglob"
|
2021-01-07 16:48:33 +02:00
|
|
|
|
|
|
|
"github.com/go-task/task/v3/internal/execext"
|
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 {
|
2019-08-21 06:33:12 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
func glob(dir string, g string) ([]string, error) {
|
|
|
|
files := make([]string, 0)
|
|
|
|
if !filepath.IsAbs(g) {
|
|
|
|
g = filepath.Join(dir, g)
|
|
|
|
}
|
|
|
|
g, err := execext.Expand(g)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
fs, err := zglob.Glob(g)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|