fix: prevent copying a directory into itself (#2608)
This commit is contained in:
1 parent
583e78b727
commit
0462b9ace3
1 file changed
+5
@@ -124,6 +124,11 @@ func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64,
|
||||
dst = newPath
|
||||
}
|
||||
|
||||
if rel, err := filepath.Rel(src, dst); err == nil && rel != "." && !strings.HasPrefix(rel, "..") {
|
||||
errs <- fmt.Errorf("cannot copy %s into a subdirectory of itself", src)
|
||||
continue
|
||||
}
|
||||
|
||||
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("walk: %w", err)
|
||||
|
||||
Reference in new issue
Block a user