]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: include the original paths in error messages
authorMohit Agarwal <mohit@sdf.org>
Mon, 16 Nov 2015 17:46:00 +0000 (23:16 +0530)
committerAlex Brainman <alex.brainman@gmail.com>
Tue, 17 Nov 2015 23:46:38 +0000 (23:46 +0000)
On Windows, Rel emits error messages of the form `Rel: can't make
\windows relative to \windows`. Rather than emitting paths after
stripping volume names, emit the original paths so as to make those of
the form `Rel: can't make d:\windows relative to c:\windows`.  Fixed a
test that expected the error message to emit clean path instead of the
original.

Fixes #13259

Change-Id: I3a9bd5b137205f22794ec8046b4e917ee48cf750
Reviewed-on: https://go-review.googlesource.com/16858
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/path/filepath/example_unix_test.go
src/path/filepath/path.go

index 27d85d15c6c5b6e9a3f41dc7d022029dd618a727..893be1b198817708b7b5bb884bcf5c671ac7a748 100644 (file)
@@ -35,7 +35,7 @@ func ExampleRel() {
        // On Unix:
        // "/a/b/c": "b/c" <nil>
        // "/b/c": "../b/c" <nil>
-       // "./b/c": "" Rel: can't make b/c relative to /a
+       // "./b/c": "" Rel: can't make ./b/c relative to /a
 }
 
 func ExampleSplit() {
index 681fdfa09fab2652ec0dd139c105ce2a4f200740..7164c070bbd6d7ee022716b3b00eae14042e9dfa 100644 (file)
@@ -270,7 +270,7 @@ func Rel(basepath, targpath string) (string, error) {
        baseSlashed := len(base) > 0 && base[0] == Separator
        targSlashed := len(targ) > 0 && targ[0] == Separator
        if baseSlashed != targSlashed || !sameWord(baseVol, targVol) {
-               return "", errors.New("Rel: can't make " + targ + " relative to " + base)
+               return "", errors.New("Rel: can't make " + targpath + " relative to " + basepath)
        }
        // Position base[b0:bi] and targ[t0:ti] at the first differing elements.
        bl := len(base)
@@ -296,7 +296,7 @@ func Rel(basepath, targpath string) (string, error) {
                t0 = ti
        }
        if base[b0:bi] == ".." {
-               return "", errors.New("Rel: can't make " + targ + " relative to " + base)
+               return "", errors.New("Rel: can't make " + targpath + " relative to " + basepath)
        }
        if b0 != bl {
                // Base elements left. Must go up before going down.