Skip to content

Commit f869fdd

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 f869fdd

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
/coverage.txt
1+
/coverage.*
22
/vendor
33
/build/

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: 19 additions & 2 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,24 @@ func TestRename(t *testing.T) {
12851286
require.NoError(t, err)
12861287
require.NoError(t, f.Close())
12871288

1288-
err = fs.Rename(oldFile, newFile)
1289-
require.NoError(t, err)
1289+
if runtime.GOOS != "windows" {
1290+
umask := syscall.Umask(2)
1291+
err = fs.Rename(oldFile, newFile)
1292+
require.NoError(t, err)
1293+
syscall.Umask(umask)
1294+
1295+
di, err := os.Stat(filepath.Dir(filepath.Join(dir, newFile)))
1296+
require.NoError(t, err)
1297+
assert.NotNil(di)
1298+
expected := 0o775
1299+
actual := int(di.Mode().Perm())
1300+
assert.Equal(
1301+
expected, actual, "Permission mismatch - expected: 0o%o, actual: 0o%o", expected, actual,
1302+
)
1303+
} else {
1304+
err = fs.Rename(oldFile, newFile)
1305+
require.NoError(t, err)
1306+
}
12901307

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

osfs/os_chroot_test.go

Lines changed: 23 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,25 @@ 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+
if runtime.GOOS == "windows" {
54+
t.Skip("Skipping POSIX umask tests on Windows")
55+
}
56+
fs, _ := setup(t)
57+
umask := syscall.Umask(2)
58+
chroot, _ := fs.Chroot("foo")
59+
f, err := chroot.Create("bar")
60+
require.NoError(t, err)
61+
require.NoError(t, f.Close())
62+
assert.Equal(t, f.Name(), "bar")
63+
syscall.Umask(umask)
64+
65+
di, err := fs.Stat("foo")
66+
require.NoError(t, err)
67+
expected := 0o775
68+
actual := int(di.Mode().Perm())
69+
assert.Equal(
70+
t, expected, actual, "Permission mismatch - expected: 0o%o, actual: 0o%o", expected, actual,
71+
)
72+
}

0 commit comments

Comments
 (0)