Preserve attributes when moving across devices (#1482)

This commit is contained in:
Joe Lim authored and GitHub committed 2023-11-06 13:57:11 +11:00
1 parent f52fffbff6
commit dcd2ea8164
2 files changed
+6 -6

No files matched your search

+4 -4
View File
@@ -36,10 +36,10 @@ func copySize(srcs []string) (int64, error) {
return total, nil return total, nil
} }
func copyFile(src, dst string, info os.FileInfo, nums chan int64) error { func copyFile(src, dst string, preserve []string, info os.FileInfo, nums chan int64) error {
var dst_mode os.FileMode = 0666 var dst_mode os.FileMode = 0666
preserve_timestamps := false preserve_timestamps := false
for _, s := range gOpts.preserve { for _, s := range preserve {
switch s { switch s {
case "timestamps": case "timestamps":
preserve_timestamps = true preserve_timestamps = true
@@ -98,7 +98,7 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
return nil return nil
} }
func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) { func copyAll(srcs []string, dstDir string, preserve []string) (nums chan int64, errs chan error) {
nums = make(chan int64, 1024) nums = make(chan int64, 1024)
errs = make(chan error, 1024) errs = make(chan error, 1024)
@@ -149,7 +149,7 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
} }
nums <- info.Size() nums <- info.Size()
} else { } else {
if err := copyFile(path, newPath, info, nums); err != nil { if err := copyFile(path, newPath, preserve, info, nums); err != nil {
errs <- fmt.Errorf("copy: %s", err) errs <- fmt.Errorf("copy: %s", err)
} }
} }
+2 -2
View File
@@ -1320,7 +1320,7 @@ func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {
nav.copyTotalChan <- total nav.copyTotalChan <- total
nums, errs := copyAll(srcs, dstDir) nums, errs := copyAll(srcs, dstDir, gOpts.preserve)
errCount := 0 errCount := 0
loop: loop:
@@ -1415,7 +1415,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {
nav.copyTotalChan <- total nav.copyTotalChan <- total
nums, errs := copyAll([]string{src}, dstDir) nums, errs := copyAll([]string{src}, dstDir, []string{"mode", "timestamps"})
oldCount := errCount oldCount := errCount
loop: loop: