From 4f45fc2cda125a580e62fb7835d5579cef1a69b9 Mon Sep 17 00:00:00 2001 From: valoq Date: Mon, 28 Sep 2026 00:01:15 +0200 Subject: [PATCH] fix: dont copy irregular files (#2618) * Fix: dont copy irregular files * improve patch --- copy.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/copy.go b/copy.go index bc6f9218..41887e61 100644 --- a/copy.go +++ b/copy.go @@ -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 })