normalizePath now always return absolute path, BasePathFs removes volume name from path

This commit is contained in:
Novan Allanadi 2019-11-11 15:31:23 +11:00 committed by Novan Allanadi
parent 5c29dbdefd
commit 952281b34e
3 changed files with 5 additions and 3 deletions

View File

@ -30,7 +30,9 @@ type BasePathFile struct {
func (f *BasePathFile) Name() string {
sourcename := f.File.Name()
return strings.TrimPrefix(sourcename, filepath.Clean(f.path))
sourcename = strings.TrimPrefix(sourcename, filepath.VolumeName(sourcename))
sourcename = strings.TrimPrefix(sourcename, filepath.Clean(f.path))
return sourcename
}
func NewBasePathFs(source Fs, path string) Fs {

View File

@ -479,7 +479,7 @@ func TestUnionFileReaddirAskForTooMany(t *testing.T) {
overlay := &MemMapFs{}
for i := 0; i < 5; i++ {
WriteFile(base, fmt.Sprintf("file%d.txt", i), []byte("afero"), 0777)
WriteFile(base, fmt.Sprintf("/file%d.txt", i), []byte("afero"), 0777)
}
ufs := &CopyOnWriteFs{base: base, layer: overlay}

View File

@ -191,7 +191,7 @@ func normalizePath(path string) (string, error) {
case FilePathSeparator:
return rootAbs, nil
default:
return path, nil
return filepath.Abs(path)
}
}