afero
afero copied to clipboard
MemMapFs.Mkdir should error if parent path does not exist
MemMapFs.Mkdir happily creates the parent path if it is missing.
&MemFs().Mkdir("/tmp/abc/def",0777) should fail, as the parent directories do not yet exist.
After about two hours debugging an issue in https://github.com/purpleidea/mgmt/ today, I realized it was in afero
, and then after reading the source, I realized that Mkdir
isn't behaving correctly. It's easy to see, since MkdirAll
behaves the same as Mkdir
.
https://github.com/spf13/afero/blob/588a75ec4f32903aa5e39a2619ba6a4631e28424/memmap.go#L149
I realized someone had to have hit this before, so a quick search in the issues found this.
It's quite important that Mkdir
doesn't make the directory if the parent isn't present. It's masking an error if it allows this!!!
Maybe someone could plug in some sort of test suite like https://github.com/pjd/pjdfstest ?
In any case, definite +1 on this bug, sorry.
I have got the same behavior. When registering with the parent directory in case that the parent directory is not found (nil) one is simply being created. But what should actually happen is that the MkDir should return a PathError.
Testing with os filesystem: