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"
|
|
|
|
|
2018-12-24 19:19:53 +02:00
|
|
|
"github.com/go-task/task/v2/internal/execext"
|
|
|
|
|
2017-09-16 16:44:13 +02:00
|
|
|
"github.com/mattn/go-zglob"
|
|
|
|
)
|
|
|
|
|
2019-08-21 06:33:12 +02:00
|
|
|
func globs(dir string, globs []string) ([]string, error){
|
|
|
|
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 {
|
2018-09-01 16:21:49 +02:00
|
|
|
continue
|
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
|
|
|
}
|
|
|
|
sort.Strings(files)
|
2019-08-21 06:33:12 +02:00
|
|
|
return files, nil
|
2017-09-16 16:44:13 +02:00
|
|
|
}
|