pkg/system: remove Umask() utility
It was only used in a couple of places, and in most places shouldn't be used as those locations were in unix/linux-only files, so didn't need the wrapper. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
59c77c8f5b
commit
4347080b46
7 changed files with 37 additions and 40 deletions
|
@ -86,9 +86,8 @@ func checkFileMode(t *testing.T, path string, perm os.FileMode) {
|
|||
}
|
||||
|
||||
func TestOverlayTarUntar(t *testing.T) {
|
||||
oldmask, err := system.Umask(0)
|
||||
assert.NilError(t, err)
|
||||
defer system.Umask(oldmask)
|
||||
restore := overrideUmask(0)
|
||||
defer restore()
|
||||
|
||||
src, err := os.MkdirTemp("", "docker-test-overlay-tar-src")
|
||||
assert.NilError(t, err)
|
||||
|
@ -125,9 +124,8 @@ func TestOverlayTarUntar(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOverlayTarAUFSUntar(t *testing.T) {
|
||||
oldmask, err := system.Umask(0)
|
||||
assert.NilError(t, err)
|
||||
defer system.Umask(oldmask)
|
||||
restore := overrideUmask(0)
|
||||
defer restore()
|
||||
|
||||
src, err := os.MkdirTemp("", "docker-test-overlay-tar-src")
|
||||
assert.NilError(t, err)
|
||||
|
|
|
@ -229,13 +229,8 @@ func applyLayerHandler(dest string, layer io.Reader, options *TarOptions, decomp
|
|||
dest = filepath.Clean(dest)
|
||||
|
||||
// We need to be able to set any perms
|
||||
if runtime.GOOS != "windows" {
|
||||
oldmask, err := system.Umask(0)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer system.Umask(oldmask)
|
||||
}
|
||||
restore := overrideUmask(0)
|
||||
defer restore()
|
||||
|
||||
if decompress {
|
||||
decompLayer, err := DecompressStream(layer)
|
||||
|
|
22
pkg/archive/diff_unix.go
Normal file
22
pkg/archive/diff_unix.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package archive
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// overrideUmask sets current process's file mode creation mask to newmask
|
||||
// and returns a function to restore it.
|
||||
//
|
||||
// WARNING for readers stumbling upon this code. Changing umask in a multi-
|
||||
// threaded environment isn't safe. Don't use this without understanding the
|
||||
// risks, and don't export this function for others to use (we shouldn't even
|
||||
// be using this ourself).
|
||||
//
|
||||
// FIXME(thaJeztah): we should get rid of these hacks if possible.
|
||||
func overrideUmask(newMask int) func() {
|
||||
oldMask := unix.Umask(newMask)
|
||||
return func() {
|
||||
unix.Umask(oldMask)
|
||||
}
|
||||
}
|
6
pkg/archive/diff_windows.go
Normal file
6
pkg/archive/diff_windows.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package archive
|
||||
|
||||
// overrideUmask is a no-op on windows.
|
||||
func overrideUmask(newmask int) func() {
|
||||
return func() {}
|
||||
}
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/containerd/containerd/pkg/userns"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
type applyLayerResponse struct {
|
||||
|
@ -42,11 +42,8 @@ func applyLayer() {
|
|||
}
|
||||
|
||||
// We need to be able to set any perms
|
||||
oldmask, err := system.Umask(0)
|
||||
defer system.Umask(oldmask)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
oldmask := unix.Umask(0)
|
||||
defer unix.Umask(oldmask)
|
||||
|
||||
if err := json.Unmarshal([]byte(os.Getenv("OPT")), &options); err != nil {
|
||||
fatal(err)
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package system // import "github.com/docker/docker/pkg/system"
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// Umask sets current process's file mode creation mask to newmask
|
||||
// and returns oldmask.
|
||||
func Umask(newmask int) (oldmask int, err error) {
|
||||
return unix.Umask(newmask), nil
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package system // import "github.com/docker/docker/pkg/system"
|
||||
|
||||
// Umask is not supported on the windows platform.
|
||||
func Umask(newmask int) (oldmask int, err error) {
|
||||
// should not be called on cli code path
|
||||
return 0, ErrNotSupportedPlatform
|
||||
}
|
Loading…
Reference in a new issue