Merge pull request #2163 from AkihiroSuda/userns-mknod

archive: fix logic for skipping mknod when running in userns
This commit is contained in:
Derek McGowan 2018-03-01 11:37:34 -08:00 committed by GitHub
commit fd6335f74d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,10 +87,6 @@ func mkdir(path string, perm os.FileMode) error {
return os.Chmod(path, perm) return os.Chmod(path, perm)
} }
func skipFile(*tar.Header) bool {
return false
}
var ( var (
inUserNS bool inUserNS bool
nsOnce sync.Once nsOnce sync.Once
@ -100,15 +96,22 @@ func setInUserNS() {
inUserNS = system.RunningInUserNS() inUserNS = system.RunningInUserNS()
} }
// handleTarTypeBlockCharFifo is an OS-specific helper function used by func skipFile(hdr *tar.Header) bool {
// createTarFile to handle the following types of header: Block; Char; Fifo switch hdr.Typeflag {
func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { case tar.TypeBlock, tar.TypeChar:
nsOnce.Do(setInUserNS)
if inUserNS {
// cannot create a device if running in user namespace // cannot create a device if running in user namespace
return nil nsOnce.Do(setInUserNS)
return inUserNS
default:
return false
} }
}
// handleTarTypeBlockCharFifo is an OS-specific helper function used by
// createTarFile to handle the following types of header: Block; Char; Fifo.
// This function must not be called for Block and Char when running in userns.
// (skipFile() should return true for them.)
func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
mode := uint32(hdr.Mode & 07777) mode := uint32(hdr.Mode & 07777)
switch hdr.Typeflag { switch hdr.Typeflag {
case tar.TypeBlock: case tar.TypeBlock: