Return nil in CopyOnWriteFs.MkdirAll when directory exists

Fixes #191
This commit is contained in:
Bjørn Erik Pedersen 2018-12-16 12:45:33 +01:00
parent 5e9f8ecaa4
commit a5d6946387
2 changed files with 7 additions and 7 deletions

View File

@ -282,7 +282,8 @@ func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error {
return u.layer.MkdirAll(name, perm) return u.layer.MkdirAll(name, perm)
} }
if dir { if dir {
return ErrFileExists // This is in line with how os.MkdirAll behaves.
return nil
} }
return u.layer.MkdirAll(name, perm) return u.layer.MkdirAll(name, perm)
} }

View File

@ -36,13 +36,12 @@ func TestCopyOnWrite(t *testing.T) {
t.Errorf("Mkdir: Got %q for %T", err, fs) t.Errorf("Mkdir: Got %q for %T", err, fs)
} }
// https://github.com/spf13/afero/issues/191 // MkdirAll does not return an error when the directory already exists
if _, ok := fs.(*OsFs); !ok {
err = fs.MkdirAll(dir, 0744) err = fs.MkdirAll(dir, 0744)
if err == nil || !os.IsExist(err) { if err != nil {
t.Errorf("MkdirAll: Got %q for %T", err, fs) t.Errorf("MkdirAll: Got %q for %T", err, fs)
} }
}
} }
} }