/
glob.go
37 lines (31 loc) · 882 Bytes
/
glob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package chezmoi
import (
"io/fs"
"github.com/bmatcuk/doublestar/v4"
vfs "github.com/twpayne/go-vfs/v5"
)
// A lstatFS implements io/fs.StatFS but uses Lstat instead of Stat.
type lstatFS struct {
wrapped interface {
fs.FS
Lstat(name string) (fs.FileInfo, error)
}
}
// Open implements io/fs.StatFS.Open.
func (s lstatFS) Open(name string) (fs.File, error) {
return s.wrapped.Open(name)
}
// Stat implements io/fs.StatFS.Stat.
func (s lstatFS) Stat(name string) (fs.FileInfo, error) {
return s.wrapped.Lstat(name)
}
// Glob is like github.com/bmatcuk/doublestar/v4.Glob except that it does not
// follow symlinks.
func Glob(fileSystem vfs.FS, prefix string) ([]string, error) {
fsys := lstatFS{wrapped: fileSystem}
opts := []doublestar.GlobOption{
doublestar.WithFailOnIOErrors(),
doublestar.WithNoFollow(),
}
return doublestar.Glob(fsys, prefix, opts...)
}