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

sftp: fix directory creation races

Lesmiscore67240bd5410a
diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go
index 37fcbdcb2..19596e59d 100644
--- a/backend/sftp/sftp.go
+++ b/backend/sftp/sftp.go
@@ -1171,6 +1171,10 @@ func (f *Fs) mkdir(ctx context.Context, dirPath string) error {
err = c.sftpClient.Mkdir(dirPath)
f.putSftpConnection(&c, err)
if err != nil {
+ if os.IsExist(err) {
+ fs.Debugf(f, "directory %q exists after Mkdir is attempted", dirPath)
+ return nil
+ }
return fmt.Errorf("mkdir %q failed: %w", dirPath, err)
}
return nil