Skip to content

osfs: max out defaultDirectoryMode so umask applies correctly #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/coverage.txt
/coverage.*
/vendor
/build/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?= v1.64.5
TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools)

Expand Down
2 changes: 1 addition & 1 deletion osfs/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
defaultDirectoryMode = 0o755
defaultDirectoryMode = 0o777
defaultCreateMode = 0o666
)

Expand Down
20 changes: 18 additions & 2 deletions osfs/os_bound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,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" {
reset_umask := umask(2)
err = fs.Rename(oldFile, newFile)
require.NoError(t, err)
reset_umask()

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)
Expand Down
22 changes: 22 additions & 0 deletions osfs/os_chroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,25 @@ func TestCapabilities(t *testing.T) {
caps := billy.Capabilities(fs)
assert.Equal(t, billy.AllCapabilities, caps)
}

func TestCreateWithChroot(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping POSIX umask tests on Windows")
}
fs, _ := setup(t)
reset_umask := 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")
reset_umask()

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,
)
}