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
|
||||
}
|
||||
newPath := filepath.Join(dst, rel)
|
||||
switch {
|
||||
case info.IsDir():
|
||||
switch info.Mode() & os.ModeType {
|
||||
case os.ModeDir:
|
||||
dstMode := os.ModePerm
|
||||
if slices.Contains(preserve, "mode") {
|
||||
dstMode = info.Mode()
|
||||
@@ -153,7 +153,7 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
|
||||
dirInfos[newPath] = info
|
||||
}
|
||||
nums <- info.Size()
|
||||
case info.Mode()&os.ModeSymlink != 0:
|
||||
case os.ModeSymlink:
|
||||
if rlink, err := os.Readlink(path); err != nil {
|
||||
errs <- fmt.Errorf("symlink: %w", err)
|
||||
} else {
|
||||
@@ -162,8 +162,12 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
|
||||
}
|
||||
}
|
||||
nums <- info.Size()
|
||||
default:
|
||||
case 0:
|
||||
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
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user