Skip to content

Commit

Permalink
Preserve attributes when moving across devices (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelim-work authored Nov 6, 2023
1 parent f52fffb commit dcd2ea8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ func copySize(srcs []string) (int64, error) {
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
preserve_timestamps := false
for _, s := range gOpts.preserve {
for _, s := range preserve {
switch s {
case "timestamps":
preserve_timestamps = true
Expand Down Expand Up @@ -98,7 +98,7 @@ func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
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)
errs = make(chan error, 1024)

Expand Down Expand Up @@ -149,7 +149,7 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
}
nums <- info.Size()
} 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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {

nav.copyTotalChan <- total

nums, errs := copyAll(srcs, dstDir)
nums, errs := copyAll(srcs, dstDir, gOpts.preserve)

errCount := 0
loop:
Expand Down Expand Up @@ -1415,7 +1415,7 @@ func (nav *nav) moveAsync(app *app, srcs []string, dstDir string) {

nav.copyTotalChan <- total

nums, errs := copyAll([]string{src}, dstDir)
nums, errs := copyAll([]string{src}, dstDir, []string{"mode", "timestamps"})

oldCount := errCount
loop:
Expand Down

0 comments on commit dcd2ea8

Please sign in to comment.