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:
parent
aeea4430d5
commit
0eba88bbfe
1 changed files with 10 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue