Debian Codegraph @

util/glob.go

raw symbols SCIP
1 package utilscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/
2
3 import (
4 "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/"
5 "sortscip-go gomod github.com/golang/go/src go1.25.0 sort/"
6 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
7
8 "github.com/go-git/go-billy/v6scip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/"
9 )
10
11 // Glob returns the names of all files matching pattern or nil
12 // if there is no matching file. The syntax of patterns is the same
13 // as in Match. The pattern may describe hierarchical names such as
14 // /usr/*/bin/ed (assuming the Separator is '/').
15 //
16 // Glob ignores file system errors such as I/O errors reading directories.
17 // The only possible returned error is ErrBadPattern, when pattern
18 // is malformed.
19 //
20 // Function originally from https://golang.org/src/path/filepath/match_test.go
21 func Globscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/Glob().(fs billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filesystemscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Filesystem#, pattern string) (matches []string, err error) {
22 if !hasMetascip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/hasMeta().(pattern) {
23 if _, err = fs.Lstatscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Symlink#Lstat.(pattern); err != nil {
24 return nil, nil
25 }
26 return []string{pattern}, nil
27 }
28
29 dir, file := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Splitscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Split().(pattern)
30 // Prevent infinite recursion. See issue 15879.
31 if dir == pattern {
32 return nil, filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.ErrBadPatternscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/ErrBadPattern.
33 }
34
35 var m []string
36 m, err = Globscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/Glob().(fs, cleanGlobPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/cleanGlobPath().(dir))
37 if err != nil {
38 return
39 }
40 for _, d := range m {
41 matches, err = globscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/glob().(fs, d, file, matches)
42 if err != nil {
43 return
44 }
45 }
46 return
47 }
48
49 // cleanGlobPath prepares path for glob matching.
50 func cleanGlobPathscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/cleanGlobPath().(path string) string {
51 switch path {
52 case "":
53 return "."
54 case string(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Separator.):
55 // do nothing to the path
56 return path
57 default:
58 return path[0 : len(path)-1] // chop off trailing separator
59 }
60 }
61
62 // glob searches for files matching pattern in the directory dir
63 // and appends them to matches. If the directory cannot be
64 // opened, it returns the existing matches. New matches are
65 // added in lexicographical order.
66 func globscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/glob().(fs billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filesystemscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Filesystem#, dir, pattern string, matches []string) (m []string, e error) {
67 m = matches
68 fi, err := fs.Statscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Basic#Stat.(dir)
69 if err != nil {
70 return
71 }
72
73 if !fi.IsDirscip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/FileInfo#IsDir().() {
74 return
75 }
76
77 names, _ := readdirnamesscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/readdirnames().(fs, dir)
78 sortscip-go gomod github.com/golang/go/src go1.25.0 sort/.Stringsscip-go gomod github.com/golang/go/src go1.25.0 sort/Strings().(names)
79
80 for _, n := range names {
81 matched, err := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Matchscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Match().(pattern, n)
82 if err != nil {
83 return m, err
84 }
85 if matched {
86 m = append(m, filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(dir, n))
87 }
88 }
89 return
90 }
91
92 // hasMeta reports whether path contains any of the magic characters
93 // recognized by Match.
94 func hasMetascip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/hasMeta().(path string) bool {
95 // TODO(niemeyer): Should other magic characters be added here?
96 return stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ContainsAnyscip-go gomod github.com/golang/go/src go1.25.0 strings/ContainsAny().(path, "*?[")
97 }
98
99 func readdirnamesscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6/util`/readdirnames().(fs billyscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/.Filesystemscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Filesystem#, dir string) ([]string, error) {
100 files, err := fs.ReadDirscip-go gomod github.com/go-git/go-billy/v6 . `github.com/go-git/go-billy/v6`/Dir#ReadDir.(dir)
101 if err != nil {
102 return nil, err
103 }
104
105 names := make([]string, 0, len(files))
106 for _, file := range files {
107 names = append(names, file.Namescip-go gomod github.com/golang/go/src go1.25.0 `io/fs`/DirEntry#Name().())
108 }
109
110 return names, nil
111 }