Skip to content

Commit

Permalink
Return os.ErrNotExist in BasePathFs on abs URLs on Windows
Browse files Browse the repository at this point in the history
So it can be used in a composite filesystem.

Fixes #162
  • Loading branch information
bep committed Apr 1, 2018
1 parent b6dc11e commit 6364489
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions basepath.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package afero

import (
"errors"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions basepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6364489

Please sign in to comment.