From 8d33ce0154ca220339166d9d65daabd2a8d7daf3 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 1 Sep 2015 20:50:28 +0100 Subject: [PATCH] Check for source and dest being the same in sync/copy/move --- fs/operations.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/operations.go b/fs/operations.go index 31175ed22..bc3c0e445 100644 --- a/fs/operations.go +++ b/fs/operations.go @@ -380,12 +380,22 @@ func readFilesMap(fs Fs) map[string]Object { return files } +// Returns true if fdst and fsrc point to the same underlying Fs +func FsSame(fdst, fsrc Fs) bool { + return fdst.Name() == fsrc.Name() && fdst.Root() == fsrc.Root() +} + // Syncs fsrc into fdst // // If Delete is true then it deletes any files in fdst that aren't in fsrc // // If DoMove is true then files will be moved instead of copied func syncCopyMove(fdst, fsrc Fs, Delete bool, DoMove bool) error { + if FsSame(fdst, fsrc) { + ErrorLog(fdst, "Nothing to do as source and destination are the same") + return nil + } + err := fdst.Mkdir() if err != nil { Stats.Error() @@ -471,6 +481,11 @@ func CopyDir(fdst, fsrc Fs) error { // Moves fsrc into fdst func MoveDir(fdst, fsrc Fs) error { + if FsSame(fdst, fsrc) { + ErrorLog(fdst, "Nothing to do as source and destination are the same") + return nil + } + // First attempt to use DirMover if fdstDirMover, ok := fdst.(DirMover); ok && fsrc.Name() == fdst.Name() { err := fdstDirMover.DirMove(fsrc)