Skip to content

Commit 767468b

Browse files
committed
osfs: max out defaultDirectoryMode
a reprise of #104, with added tests Limited the scope of the CreateWithChroot tests to OsFs, because MemFs creates parent directories with bonkers permissions. drive-by: add Makefile variables for `make test-coverage` to run successfully
1 parent 70ef9bf commit 767468b

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
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)

osfs/os_chroot_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"runtime"
10+
"syscall"
1011
"testing"
1112

1213
"github.com/go-git/go-billy/v6"
@@ -47,3 +48,27 @@ func TestCapabilities(t *testing.T) {
4748
caps := billy.Capabilities(fs)
4849
assert.Equal(t, billy.AllCapabilities, caps)
4950
}
51+
52+
func TestCreateWithChroot(t *testing.T) {
53+
fs, _ := setup(t)
54+
umask := syscall.Umask(2)
55+
chroot, _ := fs.Chroot("foo")
56+
f, err := chroot.Create("bar")
57+
require.NoError(t, err)
58+
require.NoError(t, f.Close())
59+
assert.Equal(t, f.Name(), "bar")
60+
syscall.Umask(umask)
61+
62+
di, err := fs.Stat(fs.Join("foo"))
63+
require.NoError(t, err)
64+
expected := 0o775
65+
actual := int(di.Mode().Perm())
66+
assert.Equal(
67+
t, expected, actual, "Permission mismatch - expected: 0o%o, actual: 0o%o", expected, actual,
68+
)
69+
70+
f, err = fs.Open("foo/bar")
71+
require.NoError(t, err)
72+
assert.Equal(t, f.Name(), fs.Join("foo", "bar"))
73+
require.NoError(t, f.Close())
74+
}

test/chroot_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ func eachChrootFS(t *testing.T, test func(t *testing.T, fs chrootFS)) {
2525
}
2626
}
2727

28-
func TestCreateWithChroot(t *testing.T) {
29-
eachChrootFS(t, func(t *testing.T, fs chrootFS) {
30-
t.Helper()
31-
chroot, _ := fs.Chroot("foo")
32-
f, err := chroot.Create("bar")
33-
require.NoError(t, err)
34-
require.NoError(t, f.Close())
35-
assert.Equal(t, f.Name(), "bar")
36-
37-
f, err = fs.Open("foo/bar")
38-
require.NoError(t, err)
39-
assert.Equal(t, f.Name(), fs.Join("foo", "bar"))
40-
require.NoError(t, f.Close())
41-
})
42-
}
43-
4428
func TestOpenWithChroot(t *testing.T) {
4529
eachChrootFS(t, func(t *testing.T, fs chrootFS) {
4630
t.Helper()

0 commit comments

Comments
 (0)