afero
afero copied to clipboard
WriteFile creates non-existing directory for MemMapFs but not for OsFs
The code below creates the non-existing directory "nonexistingdir" for MemMapFs but returns an error for OsFs. Shouldn't the behavior be the same?
package main
import (
"github.com/spf13/afero"
"log"
)
func main() {
memFs := afero.NewMemMapFs()
err := afero.WriteFile(memFs, "/tmp/nonexistingdir/testfile.txt", []byte("content"), 0777)
if err != nil {
log.Printf("write MemMapFs file: %v", err)
}
osFs := afero.NewOsFs()
err = afero.WriteFile(osFs, "/tmp/nonexistingdir/testfile.txt", []byte("content"), 0777)
if err != nil {
log.Printf("write OsFs file: %v", err)
}
}
Output from go run:
write OsFs file: open /tmp/nonexistingdir/testfile.txt: no such file or directory
WriteFile Before MkdirAll dir
I'm having a similar issue, is there any news on this? Essentially the MemMapFS is not returning errors when writing to a non-existant directory, in cases when a call to os.WriteFile would.
I'm having the same issue; any update?
+1
+1