Fix directory perms vs umask for tmpcopyup

Bump fileutils to v0.5.1, which fixes permissions of newly created directories
to not depend on the value of umask.

Add a test case which fails like this before the fix:

	mounts.bats
	 ✗ runc run [tmpcopyup]
	   (in test file tests/integration/mounts.bats, line 28)
	     `[[ "${lines[0]}" == *'drwxrwxrwx'* ]]' failed
	   runc spec (status=0):

	   runc run test_busybox (status=0):
	   drwxr-xr-x    2 root     root            40 Oct  4 22:35 /dir1/dir2

Fixes 3991.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2023-10-04 10:53:23 -07:00
parent d8d576ca4f
commit 730bc84418
6 changed files with 32 additions and 8 deletions
+7 -4
View File
@@ -125,6 +125,7 @@ func CopyDirectory(source string, dest string) error {
if err != nil {
return nil
}
destPath := filepath.Join(dest, relPath)
if info.IsDir() {
// Skip the source directory.
@@ -138,18 +139,20 @@ func CopyDirectory(source string, dest string) error {
uid := int(st.Uid)
gid := int(st.Gid)
if err := os.Mkdir(filepath.Join(dest, relPath), info.Mode()); err != nil {
if err := os.Mkdir(destPath, info.Mode()); err != nil {
return err
}
if err := os.Lchown(filepath.Join(dest, relPath), uid, gid); err != nil {
if err := os.Lchown(destPath, uid, gid); err != nil {
return err
}
if err := os.Chmod(destPath, info.Mode()); err != nil {
return err
}
}
return nil
}
return CopyFile(path, filepath.Join(dest, relPath))
return CopyFile(path, destPath)
})
}
+3
View File
@@ -49,6 +49,9 @@ func MkdirAllNewAs(path string, mode os.FileMode, ownerUID, ownerGID int) error
if err := os.Chown(pathComponent, ownerUID, ownerGID); err != nil {
return err
}
if err := os.Chmod(pathComponent, mode); err != nil {
return err
}
}
return nil
}
+1 -1
View File
@@ -38,7 +38,7 @@ github.com/moby/sys/mountinfo
# github.com/moby/sys/user v0.1.0
## explicit; go 1.17
github.com/moby/sys/user
# github.com/mrunalp/fileutils v0.5.0
# github.com/mrunalp/fileutils v0.5.1
## explicit; go 1.13
github.com/mrunalp/fileutils
# github.com/opencontainers/runtime-spec v1.1.1-0.20230823135140-4fec88fd00a4