]> Cypherpunks repositories - gostls13.git/commitdiff
path, path/filepath: polish documentation.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 16 Feb 2012 19:05:39 +0000 (20:05 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 16 Feb 2012 19:05:39 +0000 (20:05 +0100)
Fixes #2950.
Fixes #2951.

R=golang-dev, r
CC=golang-dev, remy
https://golang.org/cl/5672044

src/pkg/path/filepath/match.go
src/pkg/path/filepath/path.go
src/pkg/path/filepath/path_test.go
src/pkg/path/match.go
src/pkg/path/path.go

index c3678f541d4631b13f61d7c000665922535a14bc..38d264fb97aa92cf8eb4090338ff70e679317269 100644 (file)
@@ -12,6 +12,7 @@ import (
        "unicode/utf8"
 )
 
+// ErrBadPattern indicates a globbing pattern was malformed.
 var ErrBadPattern = errors.New("syntax error in pattern")
 
 // Match returns true if name matches the shell file name pattern.
@@ -33,7 +34,8 @@ var ErrBadPattern = errors.New("syntax error in pattern")
 //             lo '-' hi   matches character c for lo <= c <= hi
 //
 // Match requires pattern to match all of name, not just a substring.
-// The only possible error return occurs when the pattern is malformed.
+// The only possible returned error is ErrBadPattern, when pattern
+// is malformed.
 //
 func Match(pattern, name string) (matched bool, err error) {
 Pattern:
@@ -211,7 +213,6 @@ func getEsc(chunk string) (r rune, nchunk string, err error) {
 // if there is no matching file. The syntax of patterns is the same
 // as in Match. The pattern may describe hierarchical names such as
 // /usr/*/bin/ed (assuming the Separator is '/').
-// The only possible error return occurs when the pattern is malformed.
 //
 func Glob(pattern string) (matches []string, err error) {
        if !hasMeta(pattern) {
@@ -253,7 +254,6 @@ func Glob(pattern string) (matches []string, err error) {
 // and appends them to matches. If the directory cannot be
 // opened, it returns the existing matches. New matches are
 // added in lexicographical order.
-// The only possible error return occurs when the pattern is malformed.
 func glob(dir, pattern string, matches []string) (m []string, e error) {
        m = matches
        fi, err := os.Stat(dir)
index 3dc52aab4672873a6ab1a00b1d7f66b4174bdd5c..f468d33264bf50c2b9c0dcbf7e0d9e36f4299445 100644 (file)
@@ -36,7 +36,7 @@ const (
 // returns the string ".".
 //
 // See also Rob Pike, ``Lexical File Names in Plan 9 or
-// Getting Dot-Dot right,''
+// Getting Dot-Dot Right,''
 // http://plan9.bell-labs.com/sys/doc/lexnames.html
 func Clean(path string) string {
        vol := VolumeName(path)
@@ -118,7 +118,8 @@ func Clean(path string) string {
 }
 
 // ToSlash returns the result of replacing each separator character
-// in path with a slash ('/') character.
+// in path with a slash ('/') character. Multiple separators are
+// replaced by multiple slashes.
 func ToSlash(path string) string {
        if Separator == '/' {
                return path
@@ -127,7 +128,8 @@ func ToSlash(path string) string {
 }
 
 // FromSlash returns the result of replacing each slash ('/') character
-// in path with a separator character.
+// in path with a separator character. Multiple slashes are replaced
+// by multiple separators.
 func FromSlash(path string) string {
        if Separator == '/' {
                return path
@@ -135,7 +137,8 @@ func FromSlash(path string) string {
        return strings.Replace(path, "/", string(Separator), -1)
 }
 
-// SplitList splits a list of paths joined by the OS-specific ListSeparator.
+// SplitList splits a list of paths joined by the OS-specific ListSeparator,
+// usually found in PATH or GOPATH environment variables.
 func SplitList(path string) []string {
        if path == "" {
                return []string{}
@@ -158,7 +161,8 @@ func Split(path string) (dir, file string) {
 }
 
 // Join joins any number of path elements into a single path, adding
-// a Separator if necessary.  All empty strings are ignored.
+// a Separator if necessary. The result is Cleaned, in particular
+// all empty strings are ignored.
 func Join(elem ...string) string {
        for i, e := range elem {
                if e != "" {
@@ -183,7 +187,8 @@ func Ext(path string) string {
 
 // EvalSymlinks returns the path name after the evaluation of any symbolic
 // links.
-// If path is relative it will be evaluated relative to the current directory.
+// If path is relative the result will be relative to the current directory,
+// unless one of the components is an absolute symbolic link.
 func EvalSymlinks(path string) (string, error) {
        if runtime.GOOS == "windows" {
                // Symlinks are not supported under windows.
@@ -443,7 +448,7 @@ func Base(path string) string {
        return path
 }
 
-// Dir returns the all but the last element of path, typically the path's directory.
+// Dir returns all but the last element of path, typically the path's directory.
 // Trailing path separators are removed before processing.
 // If the path is empty, Dir returns ".".
 // If the path consists entirely of separators, Dir returns a single separator.
index 4572707aceea18cab1b54c2daaeb81c1e68340e5..6b70aa2cd7b2946d39a6442ab3f7f198d4d15537 100644 (file)
@@ -559,6 +559,7 @@ var EvalSymlinksTestDirs = []EvalSymlinksTest{
        {"test/dir/link3", "../../"},
        {"test/link1", "../test"},
        {"test/link2", "dir"},
+       {"test/linkabs", "/tmp"},
 }
 
 var EvalSymlinksTests = []EvalSymlinksTest{
@@ -571,6 +572,7 @@ var EvalSymlinksTests = []EvalSymlinksTest{
        {"test/link2/..", "test"},
        {"test/dir/link3", "."},
        {"test/link2/link3/test", "test"},
+       {"test/linkabs", "/tmp"},
 }
 
 var EvalSymlinksAbsWindowsTests = []EvalSymlinksTest{
@@ -629,6 +631,9 @@ func TestEvalSymlinks(t *testing.T) {
        for _, d := range tests {
                path := simpleJoin(tmpDir, d.path)
                dest := simpleJoin(tmpDir, d.dest)
+               if filepath.IsAbs(d.dest) {
+                       dest = d.dest
+               }
                if p, err := filepath.EvalSymlinks(path); err != nil {
                        t.Errorf("EvalSymlinks(%q) error: %v", d.path, err)
                } else if filepath.Clean(p) != filepath.Clean(dest) {
index ba7e4de321e3353ec0afa9813a44841538cfe60b..8154bf6025162104d2f205322a0a3a36fb8115b8 100644 (file)
@@ -10,6 +10,7 @@ import (
        "unicode/utf8"
 )
 
+// ErrBadPattern indicates a globbing pattern was malformed.
 var ErrBadPattern = errors.New("syntax error in pattern")
 
 // Match returns true if name matches the shell file name pattern.
@@ -31,7 +32,8 @@ var ErrBadPattern = errors.New("syntax error in pattern")
 //             lo '-' hi   matches character c for lo <= c <= hi
 //
 // Match requires pattern to match all of name, not just a substring.
-// The only possible error return is when pattern is malformed.
+// The only possible returned error is ErrBadPattern, when pattern
+// is malformed.
 //
 func Match(pattern, name string) (matched bool, err error) {
 Pattern:
index 20d89c9ff0cbcbee125e1c88ffa198cc67563ef5..13abed0b09da25120f3d920d72b658abb9e2ba83 100644 (file)
@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // Package path implements utility routines for manipulating slash-separated
-// filename paths.
+// paths.
 package path
 
 import (
@@ -25,7 +25,7 @@ import (
 // returns the string ".".
 //
 // See also Rob Pike, ``Lexical File Names in Plan 9 or
-// Getting Dot-Dot right,''
+// Getting Dot-Dot Right,''
 // http://plan9.bell-labs.com/sys/doc/lexnames.html
 func Clean(path string) string {
        if path == "" {
@@ -100,17 +100,19 @@ func Clean(path string) string {
        return string(buf[0:w])
 }
 
-// Split splits path immediately following the final path separator,
+// Split splits path immediately following the final slash.
 // separating it into a directory and file name component.
-// If there is no separator in path, Split returns an empty dir and
+// If there is no slash path, Split returns an empty dir and
 // file set to path.
+// The returned values have the property that path = dir+file.
 func Split(path string) (dir, file string) {
        i := strings.LastIndex(path, "/")
        return path[:i+1], path[i+1:]
 }
 
 // Join joins any number of path elements into a single path, adding a
-// separating slash if necessary.  All empty strings are ignored.
+// separating slash if necessary. The result is Cleaned; in particular,
+// all empty strings are ignored.
 func Join(elem ...string) string {
        for i, e := range elem {
                if e != "" {
@@ -161,11 +163,12 @@ func IsAbs(path string) bool {
        return len(path) > 0 && path[0] == '/'
 }
 
-// Dir returns the all but the last element of path, typically the path's directory.
-// Trailing path separators are removed before processing.
+// Dir returns all but the last element of path, typically the path's directory.
+// The path is Cleaned and trailing slashes are removed before processing.
 // If the path is empty, Dir returns ".".
-// If the path consists entirely of separators, Dir returns a single separator.
-// The returned path does not end in a separator unless it is the root directory.
+// If the path consists entirely of slashes followed by non-slash bytes, Dir
+// returns a single slash. In any other case, the returned path does not end in a
+// slash.
 func Dir(path string) string {
        dir, _ := Split(path)
        dir = Clean(dir)