diff --git a/basepath.go b/basepath.go index e3dcf97..083199f 100644 --- a/basepath.go +++ b/basepath.go @@ -20,16 +20,13 @@ type BasePathFs struct { path string } -// NewBasePathFs applies filepath.Clean on creation -func NewBasePathFs(source Fs, path string) *BasePathFs { - return &BasePathFs{source: source, path: filepath.Clean(path) + string(os.PathSeparator)} -} - // on a file outside the base path it returns the given file name and an error, // else the given file with the base path prepended func (b *BasePathFs) RealPath(name string) (path string, err error) { - path = filepath.Clean(filepath.Join(b.path, name)) - if !strings.HasPrefix(path, b.path) { + bpath := filepath.Clean(b.path) + string(os.PathSeparator) + + path = filepath.Clean(filepath.Join(bpath, name)) + if !strings.HasPrefix(path, bpath) { return name, os.ErrNotExist } return path, nil diff --git a/basepath_test.go b/basepath_test.go index ee9f2d3..0db6783 100644 --- a/basepath_test.go +++ b/basepath_test.go @@ -7,7 +7,7 @@ import ( func TestBasePath(t *testing.T) { baseFs := &MemMapFs{} baseFs.MkdirAll("/base/path/tmp", 0777) - bp := NewBasePathFs(baseFs, "/base/path") + bp := &BasePathFs{source: baseFs, path: "/base/path"} if _, err := bp.Create("/tmp/foo"); err != nil { t.Errorf("Failed to set real path")