mirror of
https://github.com/golang/go
synced 2024-11-25 05:47:57 -07:00
path/filepath.Glob: don't drop known matches on error.
Fixes #1610. R=rsc CC=golang-dev https://golang.org/cl/4355042
This commit is contained in:
parent
731786439c
commit
a78a25a16b
@ -241,37 +241,40 @@ func Glob(pattern string) (matches []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// glob searches for files matching pattern in the directory dir
|
// glob searches for files matching pattern in the directory dir
|
||||||
// and appends them to matches.
|
// and appends them to matches. If the directory cannot be
|
||||||
func glob(dir, pattern string, matches []string) []string {
|
// opened, it returns the existing matches. New matches are
|
||||||
|
// added in lexicographical order.
|
||||||
|
func glob(dir, pattern string, matches []string) (m []string) {
|
||||||
|
m = matches
|
||||||
fi, err := os.Stat(dir)
|
fi, err := os.Stat(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
if !fi.IsDirectory() {
|
if !fi.IsDirectory() {
|
||||||
return matches
|
return
|
||||||
}
|
}
|
||||||
d, err := os.Open(dir, os.O_RDONLY, 0666)
|
d, err := os.Open(dir, os.O_RDONLY, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
defer d.Close()
|
defer d.Close()
|
||||||
|
|
||||||
names, err := d.Readdirnames(-1)
|
names, err := d.Readdirnames(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
sort.SortStrings(names)
|
sort.SortStrings(names)
|
||||||
|
|
||||||
for _, n := range names {
|
for _, n := range names {
|
||||||
matched, err := Match(pattern, n)
|
matched, err := Match(pattern, n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return matches
|
break
|
||||||
}
|
}
|
||||||
if matched {
|
if matched {
|
||||||
matches = append(matches, Join(dir, n))
|
m = append(m, Join(dir, n))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return matches
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasMeta returns true if path contains any of the magic characters
|
// hasMeta returns true if path contains any of the magic characters
|
||||||
|
Loading…
Reference in New Issue
Block a user