diff --git a/fs/operations.go b/fs/operations.go index 3f18a6f68..520842a0e 100644 --- a/fs/operations.go +++ b/fs/operations.go @@ -1502,6 +1502,11 @@ func Rmdirs(f Fs, dir string) error { // moveOrCopyFile moves or copies a single file possibly to a new name func moveOrCopyFile(fdst Fs, fsrc Fs, dstFileName string, srcFileName string, cp bool) (err error) { + if fdst.Name() == fsrc.Name() && dstFileName == srcFileName { + Debugf(fdst, "don't need to copy/move %s, it is already at target location", dstFileName) + return nil + } + // Choose operations Op := Move if cp { diff --git a/fs/operations_test.go b/fs/operations_test.go index 0a0d84bb6..442d7cf3d 100644 --- a/fs/operations_test.go +++ b/fs/operations_test.go @@ -798,6 +798,11 @@ func TestMoveFile(t *testing.T) { require.NoError(t, err) fstest.CheckItems(t, r.flocal) fstest.CheckItems(t, r.fremote, file2) + + err = fs.MoveFile(r.fremote, r.flocal, file2.Path, file2.Path) + require.NoError(t, err) + fstest.CheckItems(t, r.flocal) + fstest.CheckItems(t, r.fremote, file2) } func TestCopyFile(t *testing.T) { @@ -819,6 +824,11 @@ func TestCopyFile(t *testing.T) { require.NoError(t, err) fstest.CheckItems(t, r.flocal, file1) fstest.CheckItems(t, r.fremote, file2) + + err = fs.CopyFile(r.fremote, r.flocal, file2.Path, file2.Path) + require.NoError(t, err) + fstest.CheckItems(t, r.flocal, file1) + fstest.CheckItems(t, r.fremote, file2) } // testFsInfo is for unit testing fs.Info