summaryrefslogtreecommitdiff
path: root/libgo/go/path
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-09-14 17:11:35 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-09-14 17:11:35 +0000
commitbc998d034f45d1828a8663b2eed928faf22a7d01 (patch)
tree8d262a22ca7318f4bcd64269fe8fe9e45bcf8d0f /libgo/go/path
parenta41a6142df74219f596e612d3a7775f68ca6e96f (diff)
libgo: update to go1.9
Reviewed-on: https://go-review.googlesource.com/63753 From-SVN: r252767
Diffstat (limited to 'libgo/go/path')
-rw-r--r--libgo/go/path/example_test.go40
-rw-r--r--libgo/go/path/filepath/match_test.go4
-rw-r--r--libgo/go/path/filepath/path.go9
-rw-r--r--libgo/go/path/filepath/path_test.go57
-rw-r--r--libgo/go/path/path.go5
5 files changed, 104 insertions, 11 deletions
diff --git a/libgo/go/path/example_test.go b/libgo/go/path/example_test.go
index 88b76557f2b..21ed1fb2fcd 100644
--- a/libgo/go/path/example_test.go
+++ b/libgo/go/path/example_test.go
@@ -13,7 +13,12 @@ import (
func ExampleBase() {
fmt.Println(path.Base("/a/b"))
- // Output: b
+ fmt.Println(path.Base("/"))
+ fmt.Println(path.Base(""))
+ // Output:
+ // b
+ // /
+ // .
}
func ExampleClean() {
@@ -24,6 +29,7 @@ func ExampleClean() {
"a/c/b/..",
"/../a/c",
"/../a/b/../././/c",
+ "",
}
for _, p := range paths {
@@ -37,16 +43,29 @@ func ExampleClean() {
// Clean("a/c/b/..") = "a/c"
// Clean("/../a/c") = "/a/c"
// Clean("/../a/b/../././/c") = "/a/c"
+ // Clean("") = "."
}
func ExampleDir() {
fmt.Println(path.Dir("/a/b/c"))
- // Output: /a/b
+ fmt.Println(path.Dir("a/b/c"))
+ fmt.Println(path.Dir("/"))
+ fmt.Println(path.Dir(""))
+ // Output:
+ // /a/b
+ // a/b
+ // /
+ // .
}
func ExampleExt() {
fmt.Println(path.Ext("/a/b/c/bar.css"))
- // Output: .css
+ fmt.Println(path.Ext("/"))
+ fmt.Println(path.Ext(""))
+ // Output:
+ // .css
+ //
+ //
}
func ExampleIsAbs() {
@@ -58,17 +77,26 @@ func ExampleJoin() {
fmt.Println(path.Join("a", "b", "c"))
fmt.Println(path.Join("a", "b/c"))
fmt.Println(path.Join("a/b", "c"))
- fmt.Println(path.Join("a/b", "/c"))
+ fmt.Println(path.Join("", ""))
+ fmt.Println(path.Join("a", ""))
+ fmt.Println(path.Join("", "a"))
// Output:
// a/b/c
// a/b/c
// a/b/c
- // a/b/c
+ //
+ // a
+ // a
}
func ExampleSplit() {
fmt.Println(path.Split("static/myfile.css"))
- // Output: static/ myfile.css
+ fmt.Println(path.Split("myfile.css"))
+ fmt.Println(path.Split(""))
+ // Output:
+ // static/ myfile.css
+ // myfile.css
+ //
}
*/
diff --git a/libgo/go/path/filepath/match_test.go b/libgo/go/path/filepath/match_test.go
index ae7ca1c228f..12d922f83bc 100644
--- a/libgo/go/path/filepath/match_test.go
+++ b/libgo/go/path/filepath/match_test.go
@@ -155,8 +155,8 @@ func TestGlob(t *testing.T) {
}
func TestGlobError(t *testing.T) {
- _, err := Glob("[7]")
- if err != nil {
+ _, err := Glob("[]")
+ if err == nil {
t.Error("expected error for bad pattern; got none")
}
}
diff --git a/libgo/go/path/filepath/path.go b/libgo/go/path/filepath/path.go
index 1d8e35c969e..c242143c7a3 100644
--- a/libgo/go/path/filepath/path.go
+++ b/libgo/go/path/filepath/path.go
@@ -4,6 +4,11 @@
// Package filepath implements utility routines for manipulating filename paths
// in a way compatible with the target operating system-defined file paths.
+//
+// The filepath package uses either forward slashes or backslashes,
+// depending on the operating system. To process paths such as URLs
+// that always use forward slashes regardless of the operating
+// system, see the path package.
package filepath
import (
@@ -461,6 +466,10 @@ func Dir(path string) string {
i--
}
dir := Clean(path[len(vol) : i+1])
+ if dir == "." && len(vol) > 2 {
+ // must be UNC
+ return vol
+ }
return vol + dir
}
diff --git a/libgo/go/path/filepath/path_test.go b/libgo/go/path/filepath/path_test.go
index 7389ea29a48..f2e92528a96 100644
--- a/libgo/go/path/filepath/path_test.go
+++ b/libgo/go/path/filepath/path_test.go
@@ -6,12 +6,14 @@ package filepath_test
import (
"errors"
+ "fmt"
"internal/testenv"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"runtime"
+ "sort"
"strings"
"testing"
)
@@ -389,7 +391,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(info os.FileInfo, err error, errors *[]error, clear bool) error {
if err != nil {
*errors = append(*errors, err)
if clear {
@@ -438,7 +440,7 @@ func TestWalk(t *testing.T) {
errors := make([]error, 0, 10)
clear := true
markFn := func(path string, info os.FileInfo, err error) error {
- return mark(path, info, err, &errors, clear)
+ return mark(info, err, &errors, clear)
}
// Expect no errors.
err := filepath.Walk(tree.name, markFn)
@@ -668,6 +670,7 @@ var windirtests = []PathTest{
{`c:\a\b`, `c:\a`},
{`c:a\b`, `c:a`},
{`c:a\b\c`, `c:a\b`},
+ {`\\host\share`, `\\host\share`},
{`\\host\share\`, `\\host\share\`},
{`\\host\share\a`, `\\host\share\`},
{`\\host\share\a\b`, `\\host\share\a`},
@@ -1330,3 +1333,53 @@ func TestBug3486(t *testing.T) { // https://golang.org/issue/3486
t.Fatalf("%q not seen", ken)
}
}
+
+func testWalkSymlink(t *testing.T, mklink func(target, link string) error) {
+ tmpdir, err := ioutil.TempDir("", "testWalkSymlink")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(tmpdir)
+
+ wd, err := os.Getwd()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.Chdir(wd)
+
+ err = os.Chdir(tmpdir)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = mklink(tmpdir, "link")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var visited []string
+ err = filepath.Walk(tmpdir, func(path string, info os.FileInfo, err error) error {
+ if err != nil {
+ t.Fatal(err)
+ }
+ rel, err := filepath.Rel(tmpdir, path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ visited = append(visited, rel)
+ return nil
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ sort.Strings(visited)
+ want := []string{".", "link"}
+ if fmt.Sprintf("%q", visited) != fmt.Sprintf("%q", want) {
+ t.Errorf("unexpected paths visited %q, want %q", visited, want)
+ }
+}
+
+func TestWalkSymlink(t *testing.T) {
+ testenv.MustHaveSymlink(t)
+ testWalkSymlink(t, os.Symlink)
+}
diff --git a/libgo/go/path/path.go b/libgo/go/path/path.go
index 76c7814c59d..5c905110a1b 100644
--- a/libgo/go/path/path.go
+++ b/libgo/go/path/path.go
@@ -5,7 +5,10 @@
// Package path implements utility routines for manipulating slash-separated
// paths.
//
-// To manipulate operating system paths, use the path/filepath package.
+// The path package should only be used for paths separated by forward
+// slashes, such as the paths in URLs. This package does not deal with
+// Windows paths with drive letters or backslashes; to manipulate
+// operating system paths, use the path/filepath package.
package path
import (