Skip to content

Commit 8ecfff5

Browse files
committed
osfs: max out defaultDirectoryMode
a reprise of #104, with added tests The tests for `ChrootFS` do not work with a memfs backend, because memfs creates parent directories with bonkers permissions. drive-by: add Makefile variables for `make test-coverage` to run successfully
1 parent 70ef9bf commit 8ecfff5

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ GOCMD = go
33
GOTEST = $(GOCMD) test
44
WASIRUN_WRAPPER := $(CURDIR)/scripts/wasirun-wrapper
55

6+
# Coverage
7+
COVERAGE_REPORT := coverage.out
8+
COVERAGE_MODE := count
9+
610
GOLANGCI_VERSION ?= v1.64.5
711
TOOLS_BIN := $(shell mkdir -p build/tools && realpath build/tools)
812

osfs/os.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
defaultDirectoryMode = 0o755
17+
defaultDirectoryMode = 0o777
1818
defaultCreateMode = 0o666
1919
)
2020

osfs/os_bound_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"path/filepath"
2626
"runtime"
2727
"strings"
28+
"syscall"
2829
"testing"
2930

3031
"github.com/go-git/go-billy/v6"
@@ -1285,8 +1286,19 @@ func TestRename(t *testing.T) {
12851286
require.NoError(t, err)
12861287
require.NoError(t, f.Close())
12871288

1289+
umask := syscall.Umask(2)
12881290
err = fs.Rename(oldFile, newFile)
12891291
require.NoError(t, err)
1292+
syscall.Umask(umask)
1293+
1294+
di, err := os.Stat(filepath.Dir(filepath.Join(dir, newFile)))
1295+
require.NoError(t, err)
1296+
assert.NotNil(di)
1297+
expected := 0o775
1298+
actual := int(di.Mode().Perm())
1299+
assert.Equal(
1300+
expected, actual, "Permission mismatch - expected: 0o%o, actual: 0o%o", expected, actual,
1301+
)
12901302

12911303
fi, err := os.Stat(filepath.Join(dir, newFile))
12921304
require.NoError(t, err)

test/chroot_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package test
33
import (
44
"fmt"
55
"os"
6+
"syscall"
67
"testing"
78

89
. "github.com/go-git/go-billy/v6" //nolint
@@ -28,11 +29,21 @@ func eachChrootFS(t *testing.T, test func(t *testing.T, fs chrootFS)) {
2829
func TestCreateWithChroot(t *testing.T) {
2930
eachChrootFS(t, func(t *testing.T, fs chrootFS) {
3031
t.Helper()
32+
umask := syscall.Umask(2)
3133
chroot, _ := fs.Chroot("foo")
3234
f, err := chroot.Create("bar")
3335
require.NoError(t, err)
3436
require.NoError(t, f.Close())
3537
assert.Equal(t, f.Name(), "bar")
38+
syscall.Umask(umask)
39+
40+
di, err := fs.Stat(fs.Join("foo"))
41+
require.NoError(t, err)
42+
expected := 0o775
43+
actual := int(di.Mode().Perm())
44+
assert.Equal(
45+
t, expected, actual, "Permission mismatch - expected: 0o%o, actual: 0o%o", expected, actual,
46+
)
3647

3748
f, err = fs.Open("foo/bar")
3849
require.NoError(t, err)

0 commit comments

Comments
 (0)