fallback to copy-del for cross-device linking

Related #151
This commit is contained in:
Gokcehan 2020-07-03 21:42:13 +03:00
parent 4d3e1cfd6e
commit e2bf773f3b

46
nav.go
View File

@ -12,6 +12,7 @@ import (
"sort"
"strconv"
"strings"
"syscall"
"time"
times "gopkg.in/djherbis/times.v1"
@ -743,9 +744,48 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
}
if err := os.Rename(src, dst); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
if err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV {
total, err := copySize([]string{src})
if err != nil {
echo.args[0] = err.Error()
ui.exprChan <- echo
continue
}
nav.copyTotalChan <- total
nums, errs := copyAll([]string{src}, dstDir)
oldCount := errCount
loop:
for {
select {
case n := <-nums:
nav.copyBytesChan <- n
case err, ok := <-errs:
if !ok {
break loop
}
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
nav.copyTotalChan <- -total
if errCount == oldCount {
if err := os.RemoveAll(src); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
} else {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
}