Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

smb: fix spurious "Directory already exists" errors when moving directories - fixes #9680

Nick Craig-Wood8772c94011cc
diff --git a/backend/smb/smb.go b/backend/smb/smb.go
index 13d800501..e858f86c4 100644
--- a/backend/smb/smb.go
+++ b/backend/smb/smb.go
@@ -439,11 +439,13 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
defer f.putConnection(&cn, err)
_, err = cn.smbShare.Stat(f.toSambaPath(dstPath))
- if os.IsNotExist(err) {
- err = cn.smbShare.Rename(f.toSambaPath(srcPath), f.toSambaPath(dstPath))
- return translateError(err, true)
+ if err == nil {
+ return fs.ErrorDirExists
+ } else if !os.IsNotExist(err) {
+ return fmt.Errorf("failed to check destination directory: %w", err)
}
- return fs.ErrorDirExists
+ err = cn.smbShare.Rename(f.toSambaPath(srcPath), f.toSambaPath(dstPath))
+ return translateError(err, true)
}
// List files and directories in a directory