From a5d6946387efe7d64d09dcba68cdd523dc1273a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 16 Dec 2018 12:45:33 +0100 Subject: [PATCH] Return nil in CopyOnWriteFs.MkdirAll when directory exists Fixes #191 --- copyOnWriteFs.go | 3 ++- copyOnWriteFs_test.go | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/copyOnWriteFs.go b/copyOnWriteFs.go index f5dd237..e8108a8 100644 --- a/copyOnWriteFs.go +++ b/copyOnWriteFs.go @@ -282,7 +282,8 @@ func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error { return u.layer.MkdirAll(name, perm) } if dir { - return ErrFileExists + // This is in line with how os.MkdirAll behaves. + return nil } return u.layer.MkdirAll(name, perm) } diff --git a/copyOnWriteFs_test.go b/copyOnWriteFs_test.go index a6cbc00..94ba725 100644 --- a/copyOnWriteFs_test.go +++ b/copyOnWriteFs_test.go @@ -36,13 +36,12 @@ func TestCopyOnWrite(t *testing.T) { t.Errorf("Mkdir: Got %q for %T", err, fs) } - // https://github.com/spf13/afero/issues/191 - if _, ok := fs.(*OsFs); !ok { - err = fs.MkdirAll(dir, 0744) - if err == nil || !os.IsExist(err) { - t.Errorf("MkdirAll: Got %q for %T", err, fs) - } + // MkdirAll does not return an error when the directory already exists + err = fs.MkdirAll(dir, 0744) + if err != nil { + t.Errorf("MkdirAll: Got %q for %T", err, fs) } + } }