Skip to content

Commit

Permalink
Merge pull request moby#38758 from thaJeztah/add_missing_char_device_…
Browse files Browse the repository at this point in the history
…mode

Graphdriver: fix "device" mode not being detected if "character-device" bit is set
  • Loading branch information
thaJeztah authored Feb 20, 2019
2 parents 7403497 + c7a38c2 commit 9688f12
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions daemon/graphdriver/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {

isHardlink := false

switch f.Mode() & os.ModeType {
case 0: // Regular file
switch mode := f.Mode(); {
case mode.IsRegular():
id := fileID{dev: stat.Dev, ino: stat.Ino}
if copyMode == Hardlink {
isHardlink = true
Expand All @@ -171,12 +171,12 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
copiedFiles[id] = dstPath
}

case os.ModeDir:
case mode.IsDir():
if err := os.Mkdir(dstPath, f.Mode()); err != nil && !os.IsExist(err) {
return err
}

case os.ModeSymlink:
case mode&os.ModeSymlink != 0:
link, err := os.Readlink(srcPath)
if err != nil {
return err
Expand All @@ -186,14 +186,14 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
return err
}

case os.ModeNamedPipe:
case mode&os.ModeNamedPipe != 0:
fallthrough
case os.ModeSocket:
case mode&os.ModeSocket != 0:
if err := unix.Mkfifo(dstPath, stat.Mode); err != nil {
return err
}

case os.ModeDevice:
case mode&os.ModeDevice != 0:
if rsystem.RunningInUserNS() {
// cannot create a device if running in user namespace
return nil
Expand All @@ -203,7 +203,7 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
}

default:
return fmt.Errorf("unknown file type for %s", srcPath)
return fmt.Errorf("unknown file type (%d / %s) for %s", f.Mode(), f.Mode().String(), srcPath)
}

// Everything below is copying metadata from src to dst. All this metadata
Expand Down

0 comments on commit 9688f12

Please sign in to comment.