diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/go/path | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.zip gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.bz2 |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/go/path')
-rw-r--r-- | libgo/go/path/filepath/example_unix_test.go | 71 | ||||
-rw-r--r-- | libgo/go/path/filepath/path_test.go | 10 | ||||
-rw-r--r-- | libgo/go/path/filepath/symlink.go | 3 | ||||
-rw-r--r-- | libgo/go/path/filepath/symlink_unix.go | 9 | ||||
-rw-r--r-- | libgo/go/path/filepath/symlink_windows.go | 99 |
5 files changed, 74 insertions, 118 deletions
diff --git a/libgo/go/path/filepath/example_unix_test.go b/libgo/go/path/filepath/example_unix_test.go index 20ec892..23f2138 100644 --- a/libgo/go/path/filepath/example_unix_test.go +++ b/libgo/go/path/filepath/example_unix_test.go @@ -94,3 +94,74 @@ func ExampleMatch() { // true <nil> // true <nil> } + +func ExampleBase() { + fmt.Println("On Unix:") + fmt.Println(filepath.Base("/foo/bar/baz.js")) + fmt.Println(filepath.Base("/foo/bar/baz")) + fmt.Println(filepath.Base("/foo/bar/baz/")) + fmt.Println(filepath.Base("dev.txt")) + fmt.Println(filepath.Base("../todo.txt")) + fmt.Println(filepath.Base("..")) + fmt.Println(filepath.Base(".")) + fmt.Println(filepath.Base("/")) + fmt.Println(filepath.Base("")) + + // Output: + // On Unix: + // baz.js + // baz + // baz + // dev.txt + // todo.txt + // .. + // . + // / + // . +} + +func ExampleDir() { + fmt.Println("On Unix:") + fmt.Println(filepath.Dir("/foo/bar/baz.js")) + fmt.Println(filepath.Dir("/foo/bar/baz")) + fmt.Println(filepath.Dir("/foo/bar/baz/")) + fmt.Println(filepath.Dir("/dirty//path///")) + fmt.Println(filepath.Dir("dev.txt")) + fmt.Println(filepath.Dir("../todo.txt")) + fmt.Println(filepath.Dir("..")) + fmt.Println(filepath.Dir(".")) + fmt.Println(filepath.Dir("/")) + fmt.Println(filepath.Dir("")) + + // Output: + // On Unix: + // /foo/bar + // /foo/bar + // /foo/bar/baz + // /dirty/path + // . + // .. + // . + // . + // / + // . +} + +func ExampleIsAbs() { + fmt.Println("On Unix:") + fmt.Println(filepath.IsAbs("/home/gopher")) + fmt.Println(filepath.IsAbs(".bashrc")) + fmt.Println(filepath.IsAbs("..")) + fmt.Println(filepath.IsAbs(".")) + fmt.Println(filepath.IsAbs("/")) + fmt.Println(filepath.IsAbs("")) + + // Output: + // On Unix: + // true + // false + // false + // false + // true + // false +} diff --git a/libgo/go/path/filepath/path_test.go b/libgo/go/path/filepath/path_test.go index 22632a0..d3f43a6 100644 --- a/libgo/go/path/filepath/path_test.go +++ b/libgo/go/path/filepath/path_test.go @@ -1381,16 +1381,6 @@ func TestIssue29372(t *testing.T) { } defer os.RemoveAll(tmpDir) - if runtime.GOOS == "windows" { - // This test is broken on windows, if temporary directory - // is a symlink. See issue 29746. - // TODO(brainman): Remove this hack once issue #29746 is fixed. - tmpDir, err = filepath.EvalSymlinks(tmpDir) - if err != nil { - t.Fatal(err) - } - } - path := filepath.Join(tmpDir, "file.txt") err = ioutil.WriteFile(path, nil, 0644) if err != nil { diff --git a/libgo/go/path/filepath/symlink.go b/libgo/go/path/filepath/symlink.go index de043c1..335b315 100644 --- a/libgo/go/path/filepath/symlink.go +++ b/libgo/go/path/filepath/symlink.go @@ -8,6 +8,7 @@ import ( "errors" "os" "runtime" + "syscall" ) func walkSymlinks(path string) (string, error) { @@ -86,7 +87,7 @@ func walkSymlinks(path string) (string, error) { if fi.Mode()&os.ModeSymlink == 0 { if !fi.Mode().IsDir() && end < len(path) { - return "", slashAfterFilePathError + return "", syscall.ENOTDIR } continue } diff --git a/libgo/go/path/filepath/symlink_unix.go b/libgo/go/path/filepath/symlink_unix.go index b57e7f2..d20e63a 100644 --- a/libgo/go/path/filepath/symlink_unix.go +++ b/libgo/go/path/filepath/symlink_unix.go @@ -2,15 +2,6 @@ package filepath -import ( - "syscall" -) - -// walkSymlinks returns slashAfterFilePathError error for paths like -// //path/to/existing_file/ and /path/to/existing_file/. and /path/to/existing_file/.. - -var slashAfterFilePathError = syscall.ENOTDIR - func evalSymlinks(path string) (string, error) { return walkSymlinks(path) } diff --git a/libgo/go/path/filepath/symlink_windows.go b/libgo/go/path/filepath/symlink_windows.go index 531dc26..a799488 100644 --- a/libgo/go/path/filepath/symlink_windows.go +++ b/libgo/go/path/filepath/symlink_windows.go @@ -5,9 +5,6 @@ package filepath import ( - "errors" - "internal/syscall/windows" - "os" "strings" "syscall" ) @@ -109,108 +106,14 @@ func toNorm(path string, normBase func(string) (string, error)) (string, error) return volume + normPath, nil } -// evalSymlinksUsingGetFinalPathNameByHandle uses Windows -// GetFinalPathNameByHandle API to retrieve the final -// path for the specified file. -func evalSymlinksUsingGetFinalPathNameByHandle(path string) (string, error) { - err := windows.LoadGetFinalPathNameByHandle() - if err != nil { - // we must be using old version of Windows - return "", err - } - - if path == "" { - return path, nil - } - - // Use Windows I/O manager to dereference the symbolic link, as per - // https://blogs.msdn.microsoft.com/oldnewthing/20100212-00/?p=14963/ - p, err := syscall.UTF16PtrFromString(path) - if err != nil { - return "", err - } - h, err := syscall.CreateFile(p, 0, 0, nil, - syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0) - if err != nil { - return "", err - } - defer syscall.CloseHandle(h) - - buf := make([]uint16, 100) - for { - n, err := windows.GetFinalPathNameByHandle(h, &buf[0], uint32(len(buf)), windows.VOLUME_NAME_DOS) - if err != nil { - return "", err - } - if n < uint32(len(buf)) { - break - } - buf = make([]uint16, n) - } - s := syscall.UTF16ToString(buf) - if len(s) > 4 && s[:4] == `\\?\` { - s = s[4:] - if len(s) > 3 && s[:3] == `UNC` { - // return path like \\server\share\... - return `\` + s[3:], nil - } - return s, nil - } - return "", errors.New("GetFinalPathNameByHandle returned unexpected path=" + s) -} - -func samefile(path1, path2 string) bool { - fi1, err := os.Lstat(path1) - if err != nil { - return false - } - fi2, err := os.Lstat(path2) - if err != nil { - return false - } - return os.SameFile(fi1, fi2) -} - -// walkSymlinks returns slashAfterFilePathError error for paths like -// //path/to/existing_file/ and /path/to/existing_file/. and /path/to/existing_file/.. - -var slashAfterFilePathError = errors.New("attempting to walk past file path.") - func evalSymlinks(path string) (string, error) { newpath, err := walkSymlinks(path) - if err == slashAfterFilePathError { - return "", syscall.ENOTDIR - } if err != nil { - newpath2, err2 := evalSymlinksUsingGetFinalPathNameByHandle(path) - if err2 == nil { - return toNorm(newpath2, normBase) - } return "", err } newpath, err = toNorm(newpath, normBase) if err != nil { - newpath2, err2 := evalSymlinksUsingGetFinalPathNameByHandle(path) - if err2 == nil { - return toNorm(newpath2, normBase) - } return "", err } - if strings.ToUpper(newpath) == strings.ToUpper(path) { - // walkSymlinks did not actually walk any symlinks, - // so we don't need to try GetFinalPathNameByHandle. - return newpath, nil - } - newpath2, err2 := evalSymlinksUsingGetFinalPathNameByHandle(path) - if err2 != nil { - return newpath, nil - } - newpath2, err2 = toNorm(newpath2, normBase) - if err2 != nil { - return newpath, nil - } - if samefile(newpath, newpath2) { - return newpath, nil - } - return newpath2, nil + return newpath, nil } |