diff --git a/.gitignore b/.gitignore index 0159b57..0b68e8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/coverage.txt +/coverage.* /vendor /build/ diff --git a/Makefile b/Makefile index de727fc..4cb55b4 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,10 @@ GOCMD = go GOTEST = $(GOCMD) test WASIRUN_WRAPPER := $(CURDIR)/scripts/wasirun-wrapper +# Coverage +COVERAGE_REPORT := coverage.out +COVERAGE_MODE := count + GOLANGCI_VERSION ?= v2.1.6 TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools) diff --git a/osfs/os.go b/osfs/os.go index 06cce49..fad85b8 100644 --- a/osfs/os.go +++ b/osfs/os.go @@ -15,7 +15,7 @@ import ( ) const ( - defaultDirectoryMode = 0o755 + defaultDirectoryMode = 0o777 defaultCreateMode = 0o666 ) diff --git a/osfs/os_bound_test.go b/osfs/os_bound_test.go index 259232b..7c18dc4 100644 --- a/osfs/os_bound_test.go +++ b/osfs/os_bound_test.go @@ -1295,8 +1295,24 @@ func TestRename(t *testing.T) { require.NoError(t, err) require.NoError(t, f.Close()) - err = fs.Rename(oldFile, newFile) - require.NoError(t, err) + if runtime.GOOS != "windows" { + resetUmask := umask(2) + err = fs.Rename(oldFile, newFile) + require.NoError(t, err) + resetUmask() + + di, err := os.Stat(filepath.Dir(filepath.Join(dir, newFile))) + require.NoError(t, err) + assert.NotNil(di) + expected := 0o775 + actual := int(di.Mode().Perm()) + assert.Equal( + expected, actual, "Permission mismatch - expected: 0o%o, actual: 0o%o", expected, actual, + ) + } else { + err = fs.Rename(oldFile, newFile) + require.NoError(t, err) + } fi, err := os.Stat(filepath.Join(dir, newFile)) require.NoError(t, err) diff --git a/osfs/os_chroot_test.go b/osfs/os_chroot_test.go index 011ec41..977bcba 100644 --- a/osfs/os_chroot_test.go +++ b/osfs/os_chroot_test.go @@ -47,3 +47,25 @@ func TestCapabilities(t *testing.T) { caps := billy.Capabilities(fs) assert.Equal(t, billy.DefaultCapabilities, caps) } + +func TestCreateWithChroot(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skipping POSIX umask tests on Windows") + } + fs, _ := setup(t) + resetUmask := umask(2) + chroot, _ := fs.Chroot("foo") + f, err := chroot.Create("bar") + require.NoError(t, err) + require.NoError(t, f.Close()) + assert.Equal(t, f.Name(), "bar") + resetUmask() + + di, err := fs.Stat("foo") + require.NoError(t, err) + expected := 0o775 + actual := int(di.Mode().Perm()) + assert.Equal( + t, expected, actual, "Permission mismatch - expected: 0o%o, actual: 0o%o", expected, actual, + ) +}