diff options
author | Rob Pike <r@golang.org> | 2011-04-01 09:58:05 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2011-04-01 09:58:05 -0700 |
commit | b5ddaa57610d9f7d145834a43efdc675821245ff (patch) | |
tree | 49a0fe8d55a35e37d751c7254ba4427669351e73 /src/pkg/path | |
parent | 759879f9bb3ef82aa8efe2d86b41ccc16f86e52d (diff) | |
download | go-b5ddaa57610d9f7d145834a43efdc675821245ff.tar.gz |
path/filepath.Glob: don't drop known matches on error.
Fixes issue 1610.
R=rsc
CC=golang-dev
http://codereview.appspot.com/4355042
Diffstat (limited to 'src/pkg/path')
-rw-r--r-- | src/pkg/path/filepath/match.go | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/pkg/path/filepath/match.go b/src/pkg/path/filepath/match.go index ad4053fa2..d1ea82b06 100644 --- a/src/pkg/path/filepath/match.go +++ b/src/pkg/path/filepath/match.go @@ -241,37 +241,40 @@ func Glob(pattern string) (matches []string) { } // glob searches for files matching pattern in the directory dir -// and appends them to matches. -func glob(dir, pattern string, matches []string) []string { +// and appends them to matches. If the directory cannot be +// 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) if err != nil { - return nil + return } if !fi.IsDirectory() { - return matches + return } d, err := os.Open(dir, os.O_RDONLY, 0666) if err != nil { - return nil + return } defer d.Close() names, err := d.Readdirnames(-1) if err != nil { - return nil + return } sort.SortStrings(names) for _, n := range names { matched, err := Match(pattern, n) if err != nil { - return matches + break } 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 |