From 728c5fbb2c08cd99611bdd9b7dbe255a6282dc9b Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Tue, 26 Feb 2019 21:25:34 +0300 Subject: [PATCH] check if src and dst are the same file before move --- nav.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nav.go b/nav.go index 32f9076..645c637 100644 --- a/nav.go +++ b/nav.go @@ -631,10 +631,23 @@ func moveAsync(ui *ui, srcs []string, dstDir string) { errCount := 0 for _, src := range srcs { + srcStat, err := os.Stat(src) + if err != nil { + errCount++ + echo.args[0] = fmt.Sprintf("[%d] error: %s", errCount, err) + ui.exprChan <- echo + continue + } + dst := filepath.Join(dstDir, filepath.Base(src)) - _, err := os.Stat(dst) - if !os.IsNotExist(err) { + dstStat, err := os.Stat(dst) + if os.SameFile(srcStat, dstStat) { + errCount++ + echo.args[0] = fmt.Sprintf("[%d] error: rename %s %s: source and destination are the same file", errCount, src, dst) + ui.exprChan <- echo + continue + } else if !os.IsNotExist(err) { var newPath string for i := 1; !os.IsNotExist(err); i++ { newPath = fmt.Sprintf("%s.~%d~", dst, i)