fix: dont copy irregular files (#2618)

* Fix: dont copy irregular files

* improve patch
This commit is contained in:
valoq authored and GitHub committed 2026-09-28 00:01:15 +02:00
1 parent 9ecf9ac660
commit 4f45fc2cda
1 file changed
+8 -4
+8 -4
View File
@@ -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
})