mirror of https://github.com/spf13/afero.git
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:
parent
b6dc11ece0
commit
63644898a8
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue