From 63644898a8da0bc22138abf860edaf5277b6102e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 1 Apr 2018 14:27:15 +0200 Subject: [PATCH] Return os.ErrNotExist in BasePathFs on abs URLs on Windows So it can be used in a composite filesystem. Fixes #162 --- basepath.go | 5 ++--- basepath_test.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/basepath.go b/basepath.go index 7fbf223..616ff8f 100644 --- a/basepath.go +++ b/basepath.go @@ -1,7 +1,6 @@ package afero import ( - "errors" "os" "path/filepath" "runtime" @@ -42,7 +41,7 @@ func NewBasePathFs(source Fs, path string) Fs { // else the given file with the base path prepended func (b *BasePathFs) RealPath(name string) (path string, err error) { if err := validateBasePathName(name); err != nil { - return "", err + return name, err } bpath := filepath.Clean(b.path) @@ -64,7 +63,7 @@ func validateBasePathName(name string) error { // On Windows a common mistake would be to provide an absolute OS path // We could strip out the base part, but that would not be very portable. if filepath.IsAbs(name) { - return &os.PathError{Op: "realPath", Path: name, Err: errors.New("got a real OS path instead of a virtual")} + return os.ErrNotExist } return nil diff --git a/basepath_test.go b/basepath_test.go index 219527d..77aa7df 100644 --- a/basepath_test.go +++ b/basepath_test.go @@ -68,8 +68,8 @@ func TestRealPath(t *testing.T) { if runtime.GOOS == "windows" { _, err = bp.RealPath(anotherDir) - if err == nil { - t.Errorf("Expected error") + if err != os.ErrNotExist { + t.Errorf("Expected os.ErrNotExist") } } else {