#209·afero

MemMapFs.MkdirAll does not set correct FileMode on intermediate directories

Author: kylhiaCreated Jun 28, 2019Updated Jun 27, 2026
Labelsbug

I have a similar use case as https://github.com/spf13/afero/pull/118. I'm using using tar and having problems with tar.FileInfoHeader. I've found that when using MemMapFs.MkdirAll only the leaf directory has a correct FileMode of os.ModeDir. The intermediate directories have a FileMode of 0.

go
func TestMemFsDirMode(t *testing.T) {
	fs := afero.NewMemMapFs()
	err := fs.MkdirAll("/sub/testDir2/foo/bar", 0644)
	if err != nil {
		t.Error(err)
	}
	info, err := fs.Stat("/sub/testDir2/foo/bar")
	if err != nil {
		t.Error(err)
	}
	if !info.IsDir() {
		t.Error("/sub/testDir2/foo/bar should be a directory")
	}
	if info.Mode()&os.ModeDir == 0 {
		t.Error("/sub/testDir2/foo/bar FileMode is not directory")
	}
	info, err = fs.Stat("/sub/testDir2/foo")
	if err != nil {
		t.Error(err)
	}
	if !info.IsDir() {
		t.Error("/sub/testDir2/foo should be a directory")
	}
	if info.Mode()&os.ModeDir == 0 {
		t.Error("/sub/testDir2/foo FileMode is not directory") //Fails
	}
}
--- FAIL: TestMemFsDirMode (0.00s)
    tar_test.go:104: /sub/testDir2/foo FileMode is not directory