afero icon indicating copy to clipboard operation
afero copied to clipboard

WriteFile creates non-existing directory for MemMapFs but not for OsFs

Open samuelnilsson opened this issue 4 years ago • 5 comments

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

samuelnilsson avatar Oct 11 '20 19:10 samuelnilsson

WriteFile Before MkdirAll dir

peterwillcn avatar Mar 13 '21 02:03 peterwillcn

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.

ahshah avatar Apr 13 '21 15:04 ahshah

I'm having the same issue; any update?

FrankDMartinez avatar Mar 18 '23 23:03 FrankDMartinez

+1

thenick775 avatar May 14 '23 04:05 thenick775

+1

cattapan avatar Oct 26 '23 12:10 cattapan