fix: dont copy irregular files (#2618)
* Fix: dont copy irregular files * improve patch
This commit is contained in:
1 parent
9ecf9ac660
commit
4f45fc2cda
1 file changed
+8
-4
@@ -140,8 +140,8 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
newPath := filepath.Join(dst, rel)
|
newPath := filepath.Join(dst, rel)
|
||||||
switch {
|
switch info.Mode() & os.ModeType {
|
||||||
case info.IsDir():
|
case os.ModeDir:
|
||||||
dstMode := os.ModePerm
|
dstMode := os.ModePerm
|
||||||
if slices.Contains(preserve, "mode") {
|
if slices.Contains(preserve, "mode") {
|
||||||
dstMode = info.Mode()
|
dstMode = info.Mode()
|
||||||
@@ -153,7 +153,7 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
|
|||||||
dirInfos[newPath] = info
|
dirInfos[newPath] = info
|
||||||
}
|
}
|
||||||
nums <- info.Size()
|
nums <- info.Size()
|
||||||
case info.Mode()&os.ModeSymlink != 0:
|
case os.ModeSymlink:
|
||||||
if rlink, err := os.Readlink(path); err != nil {
|
if rlink, err := os.Readlink(path); err != nil {
|
||||||
errs <- fmt.Errorf("symlink: %w", err)
|
errs <- fmt.Errorf("symlink: %w", err)
|
||||||
} else {
|
} else {
|
||||||
@@ -162,8 +162,12 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nums <- info.Size()
|
nums <- info.Size()
|
||||||
default:
|
case 0:
|
||||||
copyFile(path, newPath, preserve, info, nums, errs)
|
copyFile(path, newPath, preserve, info, nums, errs)
|
||||||
|
default:
|
||||||
|
// pipes, sockets and devices cannot be copied like regular files
|
||||||
|
errs <- fmt.Errorf("cannot copy irregular file %s (named pipe, socket or device)", path)
|
||||||
|
nums <- info.Size()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user