mirror of https://github.com/spf13/afero.git
ReadOnlyFs: MkdirAll on existing path should return nil
This commit is contained in:
parent
100c9a6d7b
commit
371e51f7c3
|
@ -88,6 +88,10 @@ func (r *ReadOnlyFs) Mkdir(n string, p os.FileMode) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error {
|
func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error {
|
||||||
|
fi, err := r.source.Stat(n)
|
||||||
|
if err == nil && fi.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return syscall.EPERM
|
return syscall.EPERM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package afero
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMkdirAllReadonly(t *testing.T) {
|
||||||
|
base := &MemMapFs{}
|
||||||
|
ro := &ReadOnlyFs{source: base}
|
||||||
|
|
||||||
|
base.MkdirAll("/home/test", 0o777)
|
||||||
|
if err := ro.MkdirAll("/home/test", 0o777); err != nil {
|
||||||
|
t.Errorf("Failed to MkdirAll on existing path in ReadOnlyFs: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ro.MkdirAll("/home/test/newdir", 0o777); err == nil {
|
||||||
|
t.Error("Creating new dir with MkdirAll on ReadOnlyFs should fail but returned nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Create("/home/test/file")
|
||||||
|
if err := ro.MkdirAll("/home/test/file", 0o777); err == nil {
|
||||||
|
t.Error("Creating new dir with MkdirAll on ReadOnlyFs where a file already exists should fail but returned nil")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue