aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/path
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-01-14 00:05:42 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-01-14 00:05:42 +0000
commitc2047754c300b68c05d65faa8dc2925fe67b71b4 (patch)
treee183ae81a1f48a02945cb6de463a70c5be1b06f6 /libgo/go/path
parent829afb8f05602bb31c9c597b24df7377fed4f059 (diff)
downloadgcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.zip
gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.gz
gcc-c2047754c300b68c05d65faa8dc2925fe67b71b4.tar.bz2
libgo: update to Go 1.8 release candidate 1
Compiler changes: * Change map assignment to use mapassign and assign value directly. * Change string iteration to use decoderune, faster for ASCII strings. * Change makeslice to take int, and use makeslice64 for larger values. * Add new noverflow field to hmap struct used for maps. Unresolved problems, to be fixed later: * Commented out test in go/types/sizes_test.go that doesn't compile. * Commented out reflect.TestStructOf test for padding after zero-sized field. Reviewed-on: https://go-review.googlesource.com/35231 gotools/: Updates for Go 1.8rc1. * Makefile.am (go_cmd_go_files): Add bug.go. (s-zdefaultcc): Write defaultPkgConfig. * Makefile.in: Rebuild. From-SVN: r244456
Diffstat (limited to 'libgo/go/path')
-rw-r--r--libgo/go/path/filepath/match.go18
-rw-r--r--libgo/go/path/filepath/match_test.go11
-rw-r--r--libgo/go/path/filepath/path.go11
-rw-r--r--libgo/go/path/filepath/path_plan9.go3
-rw-r--r--libgo/go/path/filepath/path_test.go103
-rw-r--r--libgo/go/path/filepath/path_unix.go3
-rw-r--r--libgo/go/path/filepath/path_windows.go11
-rw-r--r--libgo/go/path/filepath/symlink.go5
-rw-r--r--libgo/go/path/filepath/symlink_windows.go2
-rw-r--r--libgo/go/path/path.go2
10 files changed, 124 insertions, 45 deletions
diff --git a/libgo/go/path/filepath/match.go b/libgo/go/path/filepath/match.go
index 9fa68f5..5168e03 100644
--- a/libgo/go/path/filepath/match.go
+++ b/libgo/go/path/filepath/match.go
@@ -240,13 +240,14 @@ func Glob(pattern string) (matches []string, err error) {
}
dir, file := Split(pattern)
+ volumeLen := 0
if runtime.GOOS == "windows" {
- dir = cleanGlobPathWindows(dir)
+ volumeLen, dir = cleanGlobPathWindows(dir)
} else {
dir = cleanGlobPath(dir)
}
- if !hasMeta(dir) {
+ if !hasMeta(dir[volumeLen:]) {
return glob(dir, file, nil)
}
@@ -283,18 +284,21 @@ func cleanGlobPath(path string) string {
}
// cleanGlobPathWindows is windows version of cleanGlobPath.
-func cleanGlobPathWindows(path string) string {
+func cleanGlobPathWindows(path string) (prefixLen int, cleaned string) {
vollen := volumeNameLen(path)
switch {
case path == "":
- return "."
+ return 0, "."
case vollen+1 == len(path) && os.IsPathSeparator(path[len(path)-1]): // /, \, C:\ and C:/
// do nothing to the path
- return path
+ return vollen + 1, path
case vollen == len(path) && len(path) == 2: // C:
- return path + "." // convert C: into C:.
+ return vollen, path + "." // convert C: into C:.
default:
- return path[0 : len(path)-1] // chop off trailing separator
+ if vollen >= len(path) {
+ vollen = len(path) - 1
+ }
+ return vollen, path[0 : len(path)-1] // chop off trailing separator
}
}
diff --git a/libgo/go/path/filepath/match_test.go b/libgo/go/path/filepath/match_test.go
index 102eb1c..ae7ca1c 100644
--- a/libgo/go/path/filepath/match_test.go
+++ b/libgo/go/path/filepath/match_test.go
@@ -6,6 +6,7 @@ package filepath_test
import (
"fmt"
+ "internal/testenv"
"io/ioutil"
"os"
. "path/filepath"
@@ -175,15 +176,7 @@ var globSymlinkTests = []struct {
}
func TestGlobSymlink(t *testing.T) {
- switch runtime.GOOS {
- case "android", "nacl", "plan9":
- t.Skipf("skipping on %s", runtime.GOOS)
- case "windows":
- if !supportsSymlinks {
- t.Skipf("skipping on %s", runtime.GOOS)
- }
-
- }
+ testenv.MustHaveSymlink(t)
tmpDir, err := ioutil.TempDir("", "globsymlink")
if err != nil {
diff --git a/libgo/go/path/filepath/path.go b/libgo/go/path/filepath/path.go
index 0dc559c..1d8e35c 100644
--- a/libgo/go/path/filepath/path.go
+++ b/libgo/go/path/filepath/path.go
@@ -177,7 +177,7 @@ func FromSlash(path string) string {
// SplitList splits a list of paths joined by the OS-specific ListSeparator,
// usually found in PATH or GOPATH environment variables.
// Unlike strings.Split, SplitList returns an empty slice when passed an empty
-// string. SplitList does not replace slash characters in the returned paths.
+// string.
func SplitList(path string) []string {
return splitList(path)
}
@@ -393,9 +393,14 @@ func walk(path string, info os.FileInfo, walkFn WalkFunc) error {
func Walk(root string, walkFn WalkFunc) error {
info, err := os.Lstat(root)
if err != nil {
- return walkFn(root, nil, err)
+ err = walkFn(root, nil, err)
+ } else {
+ err = walk(root, info, walkFn)
}
- return walk(root, info, walkFn)
+ if err == SkipDir {
+ return nil
+ }
+ return err
}
// readDirNames reads the directory named by dirname and returns
diff --git a/libgo/go/path/filepath/path_plan9.go b/libgo/go/path/filepath/path_plan9.go
index 60d46d9..ec792fc 100644
--- a/libgo/go/path/filepath/path_plan9.go
+++ b/libgo/go/path/filepath/path_plan9.go
@@ -18,6 +18,9 @@ func volumeNameLen(path string) int {
}
// HasPrefix exists for historical compatibility and should not be used.
+//
+// Deprecated: HasPrefix does not respect path boundaries and
+// does not ignore case when required.
func HasPrefix(p, prefix string) bool {
return strings.HasPrefix(p, prefix)
}
diff --git a/libgo/go/path/filepath/path_test.go b/libgo/go/path/filepath/path_test.go
index 9c3f287..7389ea2 100644
--- a/libgo/go/path/filepath/path_test.go
+++ b/libgo/go/path/filepath/path_test.go
@@ -6,6 +6,7 @@ package filepath_test
import (
"errors"
+ "internal/testenv"
"io/ioutil"
"os"
"path/filepath"
@@ -15,8 +16,6 @@ import (
"testing"
)
-var supportsSymlinks = true
-
type PathTest struct {
path, result string
}
@@ -532,7 +531,7 @@ func TestWalkSkipDirOnFile(t *testing.T) {
touch(t, filepath.Join(td, "dir/foo2"))
sawFoo2 := false
- filepath.Walk(td, func(path string, info os.FileInfo, err error) error {
+ walker := func(path string, info os.FileInfo, err error) error {
if strings.HasSuffix(path, "foo2") {
sawFoo2 = true
}
@@ -540,8 +539,20 @@ func TestWalkSkipDirOnFile(t *testing.T) {
return filepath.SkipDir
}
return nil
- })
+ }
+
+ err = filepath.Walk(td, walker)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if sawFoo2 {
+ t.Errorf("SkipDir on file foo1 did not block processing of foo2")
+ }
+ err = filepath.Walk(filepath.Join(td, "dir"), walker)
+ if err != nil {
+ t.Fatal(err)
+ }
if sawFoo2 {
t.Errorf("SkipDir on file foo1 did not block processing of foo2")
}
@@ -779,13 +790,7 @@ func simpleJoin(dir, path string) string {
}
func TestEvalSymlinks(t *testing.T) {
- switch runtime.GOOS {
- case "android", "nacl", "plan9":
- t.Skipf("skipping on %s", runtime.GOOS)
- }
- if !supportsSymlinks {
- t.Skip("skipping because symlinks are not supported")
- }
+ testenv.MustHaveSymlink(t)
tmpDir, err := ioutil.TempDir("", "evalsymlink")
if err != nil {
@@ -875,6 +880,40 @@ func TestEvalSymlinks(t *testing.T) {
t.Errorf(`EvalSymlinks(".") in %q directory returns %q, want "." or %q`, d.path, p, want)
}()
+ // test EvalSymlinks("C:.") on Windows
+ if runtime.GOOS == "windows" {
+ func() {
+ defer func() {
+ err := os.Chdir(wd)
+ if err != nil {
+ t.Fatal(err)
+ }
+ }()
+
+ err := os.Chdir(path)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ volDot := filepath.VolumeName(tmpDir) + "."
+
+ p, err := filepath.EvalSymlinks(volDot)
+ if err != nil {
+ t.Errorf(`EvalSymlinks("%s") in %q directory error: %v`, volDot, d.path, err)
+ return
+ }
+ if p == volDot {
+ return
+ }
+ want := filepath.Clean(findEvalSymlinksTestDirsDest(t, testdirs, d.path))
+ if p == want {
+ return
+ }
+ t.Errorf(`EvalSymlinks("%s") in %q directory returns %q, want %q or %q`, volDot, d.path, p, volDot, want)
+ }()
+ }
+
// test EvalSymlinks(".."+path)
func() {
defer func() {
@@ -926,14 +965,30 @@ func TestEvalSymlinks(t *testing.T) {
}
}
-func TestIssue13582(t *testing.T) {
- switch runtime.GOOS {
- case "android", "nacl", "plan9":
- t.Skipf("skipping on %s", runtime.GOOS)
+func TestEvalSymlinksIsNotExist(t *testing.T) {
+ testenv.MustHaveSymlink(t)
+
+ defer chtmpdir(t)()
+
+ _, err := filepath.EvalSymlinks("notexist")
+ if !os.IsNotExist(err) {
+ t.Errorf("expected the file is not found, got %v\n", err)
+ }
+
+ err = os.Symlink("notexist", "link")
+ if err != nil {
+ t.Fatal(err)
}
- if !supportsSymlinks {
- t.Skip("skipping because symlinks are not supported")
+ defer os.Remove("link")
+
+ _, err = filepath.EvalSymlinks("link")
+ if !os.IsNotExist(err) {
+ t.Errorf("expected the file is not found, got %v\n", err)
}
+}
+
+func TestIssue13582(t *testing.T) {
+ testenv.MustHaveSymlink(t)
tmpDir, err := ioutil.TempDir("", "issue13582")
if err != nil {
@@ -1009,13 +1064,16 @@ var absTestDirs = []string{
var absTests = []string{
".",
"b",
+ "b/",
"../a",
"../a/b",
"../a/b/./c/../../.././a",
+ "../a/b/./c/../../.././a/",
"$",
"$/.",
"$/a/../a/b",
"$/a/b/c/../../.././a",
+ "$/a/b/c/../../.././a/",
}
func TestAbs(t *testing.T) {
@@ -1080,7 +1138,7 @@ func TestAbs(t *testing.T) {
if !filepath.IsAbs(abspath) {
t.Errorf("Abs(%q)=%q, not an absolute path", path, abspath)
}
- if filepath.IsAbs(path) && abspath != filepath.Clean(path) {
+ if filepath.IsAbs(abspath) && abspath != filepath.Clean(abspath) {
t.Errorf("Abs(%q)=%q, isn't clean", path, abspath)
}
}
@@ -1244,11 +1302,11 @@ func TestBug3486(t *testing.T) { // https://golang.org/issue/3486
if err != nil {
t.Fatal(err)
}
- bugs := filepath.Join(root, "bugs")
+ bugs := filepath.Join(root, "fixedbugs")
ken := filepath.Join(root, "ken")
seenBugs := false
seenKen := false
- filepath.Walk(root, func(pth string, info os.FileInfo, err error) error {
+ err = filepath.Walk(root, func(pth string, info os.FileInfo, err error) error {
if err != nil {
t.Fatal(err)
}
@@ -1259,12 +1317,15 @@ func TestBug3486(t *testing.T) { // https://golang.org/issue/3486
return filepath.SkipDir
case ken:
if !seenBugs {
- t.Fatal("filepath.Walk out of order - ken before bugs")
+ t.Fatal("filepath.Walk out of order - ken before fixedbugs")
}
seenKen = true
}
return nil
})
+ if err != nil {
+ t.Fatal(err)
+ }
if !seenKen {
t.Fatalf("%q not seen", ken)
}
diff --git a/libgo/go/path/filepath/path_unix.go b/libgo/go/path/filepath/path_unix.go
index 2d242cc..d77ff24 100644
--- a/libgo/go/path/filepath/path_unix.go
+++ b/libgo/go/path/filepath/path_unix.go
@@ -20,6 +20,9 @@ func volumeNameLen(path string) int {
}
// HasPrefix exists for historical compatibility and should not be used.
+//
+// Deprecated: HasPrefix does not respect path boundaries and
+// does not ignore case when required.
func HasPrefix(p, prefix string) bool {
return strings.HasPrefix(p, prefix)
}
diff --git a/libgo/go/path/filepath/path_windows.go b/libgo/go/path/filepath/path_windows.go
index 41c57df..0d8b620 100644
--- a/libgo/go/path/filepath/path_windows.go
+++ b/libgo/go/path/filepath/path_windows.go
@@ -37,7 +37,7 @@ func volumeNameLen(path string) int {
if path[1] == ':' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
return 2
}
- // is it UNC
+ // is it UNC? https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
if l := len(path); l >= 5 && isSlash(path[0]) && isSlash(path[1]) &&
!isSlash(path[2]) && path[2] != '.' {
// first, leading `\\` and next shouldn't be `\`. its server name.
@@ -65,6 +65,9 @@ func volumeNameLen(path string) int {
}
// HasPrefix exists for historical compatibility and should not be used.
+//
+// Deprecated: HasPrefix does not respect path boundaries and
+// does not ignore case when required.
func HasPrefix(p, prefix string) bool {
if strings.HasPrefix(p, prefix) {
return true
@@ -106,7 +109,11 @@ func splitList(path string) []string {
}
func abs(path string) (string, error) {
- return syscall.FullPath(path)
+ fullPath, err := syscall.FullPath(path)
+ if err != nil {
+ return "", err
+ }
+ return Clean(fullPath), nil
}
func join(elem []string) string {
diff --git a/libgo/go/path/filepath/symlink.go b/libgo/go/path/filepath/symlink.go
index f627a94..824aee4 100644
--- a/libgo/go/path/filepath/symlink.go
+++ b/libgo/go/path/filepath/symlink.go
@@ -105,8 +105,9 @@ func walkSymlinks(path string) (string, error) {
// directory is a symlink. Stop the walk, if symlink
// target is not absolute path, and return "."
// to the caller (just like unix does).
- if path == "." && !IsAbs(newpath) {
- return ".", nil
+ // Same for "C:.".
+ if path[volumeNameLen(path):] == "." && !IsAbs(newpath) {
+ return path, nil
}
}
if i == linksWalked {
diff --git a/libgo/go/path/filepath/symlink_windows.go b/libgo/go/path/filepath/symlink_windows.go
index bb05aab..f771fe3 100644
--- a/libgo/go/path/filepath/symlink_windows.go
+++ b/libgo/go/path/filepath/symlink_windows.go
@@ -47,7 +47,7 @@ func baseIsDotDot(path string) bool {
return path[i+1:] == ".."
}
-// toNorm returns the normalized path that is guranteed to be unique.
+// toNorm returns the normalized path that is guaranteed to be unique.
// It should accept the following formats:
// * UNC paths (e.g \\server\share\foo\bar)
// * absolute paths (e.g C:\foo\bar)
diff --git a/libgo/go/path/path.go b/libgo/go/path/path.go
index c1d4d8a..76c7814 100644
--- a/libgo/go/path/path.go
+++ b/libgo/go/path/path.go
@@ -4,6 +4,8 @@
// Package path implements utility routines for manipulating slash-separated
// paths.
+//
+// To manipulate operating system paths, use the path/filepath package.
package path
import (