1
mirror of https://github.com/rclone/rclone synced 2024-09-15 11:38:53 +02:00

sftp: check directory is empty before issuing rmdir

Some SFTP servers allow rmdir on full directories which is allowed
according to the RFC so make sure we don't accidentally delete data
here.

See: https://forum.rclone.org/t/rmdir-and-delete-empty-src-dirs-file-does-not-exist/7737
This commit is contained in:
Nick Craig-Wood 2018-11-30 17:37:55 +00:00
parent aeea4430d5
commit 0eba88bbfe

View File

@ -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 {