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: check directory is empty before issuing rmdir

Nick Craig-Wood0eba88bbfe44
diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go
index cfa6d4007..e37d83f9c 100644
--- a/backend/sftp/sftp.go
+++ b/backend/sftp/sftp.go
@@ -594,6 +594,16 @@ func (f *Fs) Mkdir(dir string) error {
// Rmdir removes the root directory of the Fs object
func (f *Fs) Rmdir(dir string) error {
+ // Check to see if directory is empty as some servers will
+ // delete recursively with RemoveDirectory
+ entries, err := f.List(dir)
+ if err != nil {
+ return errors.Wrap(err, "Rmdir")
+ }
+ if len(entries) != 0 {
+ return fs.ErrorDirectoryNotEmpty
+ }
+ // Remove the directory
root := path.Join(f.root, dir)
c, err := f.getSftpConnection()
if err != nil {