diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-13 19:16:27 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-13 19:16:27 +0000 |
commit | 7b1c3dd9e670da2041ff1af415999310f88888ad (patch) | |
tree | c5132538d5da85ed816c7e1f9d93c4a503b838ab /libgo/go/path | |
parent | 36cfbee133027429a681ce585643d38228ab1213 (diff) | |
download | gcc-7b1c3dd9e670da2041ff1af415999310f88888ad.zip gcc-7b1c3dd9e670da2041ff1af415999310f88888ad.tar.gz gcc-7b1c3dd9e670da2041ff1af415999310f88888ad.tar.bz2 |
libgo: Update to weekly.2011-12-02.
From-SVN: r182295
Diffstat (limited to 'libgo/go/path')
-rw-r--r-- | libgo/go/path/filepath/match.go | 2 | ||||
-rw-r--r-- | libgo/go/path/filepath/path.go | 38 | ||||
-rw-r--r-- | libgo/go/path/filepath/path_test.go | 21 |
3 files changed, 35 insertions, 26 deletions
diff --git a/libgo/go/path/filepath/match.go b/libgo/go/path/filepath/match.go index 8cf1f9a..c3678f5 100644 --- a/libgo/go/path/filepath/match.go +++ b/libgo/go/path/filepath/match.go @@ -260,7 +260,7 @@ func glob(dir, pattern string, matches []string) (m []string, e error) { if err != nil { return } - if !fi.IsDirectory() { + if !fi.IsDir() { return } d, err := os.Open(dir) diff --git a/libgo/go/path/filepath/path.go b/libgo/go/path/filepath/path.go index 1b5d6c3..e3d6c34 100644 --- a/libgo/go/path/filepath/path.go +++ b/libgo/go/path/filepath/path.go @@ -223,7 +223,7 @@ func EvalSymlinks(path string) (string, error) { if err != nil { return "", err } - if !fi.IsSymlink() { + if fi.Mode()&os.ModeSymlink == 0 { b.WriteString(p) if path != "" { b.WriteRune(Separator) @@ -312,7 +312,11 @@ func Rel(basepath, targpath string) (string, error) { if b0 != bl { // Base elements left. Must go up before going down. seps := strings.Count(base[b0:bl], string(Separator)) - buf := make([]byte, 3+seps*3+tl-t0) + size := 2 + seps*3 + if tl != t0 { + size += 1 + tl - t0 + } + buf := make([]byte, size) n := copy(buf, "..") for i := 0; i < seps; i++ { buf[n] = Separator @@ -341,19 +345,19 @@ var SkipDir = errors.New("skip this directory") // sole exception is that if path is a directory and the function returns the // special value SkipDir, the contents of the directory are skipped // and processing continues as usual on the next file. -type WalkFunc func(path string, info *os.FileInfo, err error) error +type WalkFunc func(path string, info os.FileInfo, err error) error // walk recursively descends path, calling w. -func walk(path string, info *os.FileInfo, walkFn WalkFunc) error { +func walk(path string, info os.FileInfo, walkFn WalkFunc) error { err := walkFn(path, info, nil) if err != nil { - if info.IsDirectory() && err == SkipDir { + if info.IsDir() && err == SkipDir { return nil } return err } - if !info.IsDirectory() { + if !info.IsDir() { return nil } @@ -363,7 +367,7 @@ func walk(path string, info *os.FileInfo, walkFn WalkFunc) error { } for _, fileInfo := range list { - if err = walk(Join(path, fileInfo.Name), fileInfo, walkFn); err != nil { + if err = walk(Join(path, fileInfo.Name()), fileInfo, walkFn); err != nil { return err } } @@ -386,7 +390,7 @@ func Walk(root string, walkFn WalkFunc) error { // readDir reads the directory named by dirname and returns // a sorted list of directory entries. // Copied from io/ioutil to avoid the circular import. -func readDir(dirname string) ([]*os.FileInfo, error) { +func readDir(dirname string) ([]os.FileInfo, error) { f, err := os.Open(dirname) if err != nil { return nil, err @@ -396,20 +400,16 @@ func readDir(dirname string) ([]*os.FileInfo, error) { if err != nil { return nil, err } - fi := make(fileInfoList, len(list)) - for i := range list { - fi[i] = &list[i] - } - sort.Sort(fi) - return fi, nil + sort.Sort(byName(list)) + return list, nil } -// A dirList implements sort.Interface. -type fileInfoList []*os.FileInfo +// byName implements sort.Interface. +type byName []os.FileInfo -func (f fileInfoList) Len() int { return len(f) } -func (f fileInfoList) Less(i, j int) bool { return f[i].Name < f[j].Name } -func (f fileInfoList) Swap(i, j int) { f[i], f[j] = f[j], f[i] } +func (f byName) Len() int { return len(f) } +func (f byName) Less(i, j int) bool { return f[i].Name() < f[j].Name() } +func (f byName) Swap(i, j int) { f[i], f[j] = f[j], f[i] } // Base returns the last element of path. // Trailing path separators are removed before extracting the last element. diff --git a/libgo/go/path/filepath/path_test.go b/libgo/go/path/filepath/path_test.go index c81cbf0..2bd62d3 100644 --- a/libgo/go/path/filepath/path_test.go +++ b/libgo/go/path/filepath/path_test.go @@ -317,7 +317,7 @@ func checkMarks(t *testing.T, report bool) { // Assumes that each node name is unique. Good enough for a test. // If clear is true, any incoming error is cleared before return. The errors // are always accumulated, though. -func mark(path string, info *os.FileInfo, err error, errors *[]error, clear bool) error { +func mark(path string, info os.FileInfo, err error, errors *[]error, clear bool) error { if err != nil { *errors = append(*errors, err) if clear { @@ -325,8 +325,9 @@ func mark(path string, info *os.FileInfo, err error, errors *[]error, clear bool } return err } + name := info.Name() walkTree(tree, tree.name, func(path string, n *Node) { - if n.name == info.Name { + if n.name == name { n.mark++ } }) @@ -337,7 +338,7 @@ func TestWalk(t *testing.T) { makeTree(t) errors := make([]error, 0, 10) clear := true - markFn := func(path string, info *os.FileInfo, err error) error { + markFn := func(path string, info os.FileInfo, err error) error { return mark(path, info, err, &errors, clear) } // Expect no errors. @@ -548,7 +549,7 @@ func TestEvalSymlinks(t *testing.T) { // relative testEvalSymlinks(t, tests) // absolute -/* These tests do not work in the gccgo test environment. + /* These tests do not work in the gccgo test environment. goroot, err := filepath.EvalSymlinks(os.Getenv("GOROOT")) if err != nil { t.Fatalf("EvalSymlinks(%q) error: %v", os.Getenv("GOROOT"), err) @@ -564,7 +565,7 @@ func TestEvalSymlinks(t *testing.T) { } } testEvalSymlinks(t, tests) -*/ + */ } /* These tests do not work in the gccgo test environment. @@ -603,7 +604,7 @@ func TestAbs(t *testing.T) { t.Errorf("Abs(%q) error: %v", path, err) } absinfo, err := os.Stat(abspath) - if err != nil || absinfo.Ino != info.Ino { + if err != nil || !absinfo.(*os.FileStat).SameFile(info.(*os.FileStat)) { t.Errorf("Abs(%q)=%q, not the same file", path, abspath) } if !filepath.IsAbs(abspath) { @@ -634,6 +635,10 @@ var reltests = []RelTests{ {"a/b/../c", "a/b", "../b"}, {"a/b/c", "a/c/d", "../../c/d"}, {"a/b", "c/d", "../../c/d"}, + {"a/b/c/d", "a/b", "../.."}, + {"a/b/c/d", "a/b/", "../.."}, + {"a/b/c/d/", "a/b", "../.."}, + {"a/b/c/d/", "a/b/", "../.."}, {"../../a/b", "../../a/b/c/d", "c/d"}, {"/a/b", "/a/b", "."}, {"/a/b/.", "/a/b", "."}, @@ -645,6 +650,10 @@ var reltests = []RelTests{ {"/a/b/../c", "/a/b", "../b"}, {"/a/b/c", "/a/c/d", "../../c/d"}, {"/a/b", "/c/d", "../../c/d"}, + {"/a/b/c/d", "/a/b", "../.."}, + {"/a/b/c/d", "/a/b/", "../.."}, + {"/a/b/c/d/", "/a/b", "../.."}, + {"/a/b/c/d/", "/a/b/", "../.."}, {"/../../a/b", "/../../a/b/c/d", "c/d"}, {".", "a/b", "a/b"}, {".", "..", ".."}, |