Return os.ErrNotExist in BasePathFs on abs URLs on Windows

So it can be used in a composite filesystem.

Fixes #162
This commit is contained in:
Bjørn Erik Pedersen 2018-04-01 14:27:15 +02:00
parent b6dc11ece0
commit 63644898a8
No known key found for this signature in database
GPG Key ID: 330E6E2BD4859D8F
2 changed files with 4 additions and 5 deletions

View File

@ -1,7 +1,6 @@
package afero package afero
import ( import (
"errors"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -42,7 +41,7 @@ func NewBasePathFs(source Fs, path string) Fs {
// else the given file with the base path prepended // else the given file with the base path prepended
func (b *BasePathFs) RealPath(name string) (path string, err error) { func (b *BasePathFs) RealPath(name string) (path string, err error) {
if err := validateBasePathName(name); err != nil { if err := validateBasePathName(name); err != nil {
return "", err return name, err
} }
bpath := filepath.Clean(b.path) 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 // 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. // We could strip out the base part, but that would not be very portable.
if filepath.IsAbs(name) { 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 return nil

View File

@ -68,8 +68,8 @@ func TestRealPath(t *testing.T) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
_, err = bp.RealPath(anotherDir) _, err = bp.RealPath(anotherDir)
if err == nil { if err != os.ErrNotExist {
t.Errorf("Expected error") t.Errorf("Expected os.ErrNotExist")
} }
} else { } else {