forked from TrueCloudLab/rclone
onedrive: fix rmdir sometimes deleting directories with contents
Before this change we were using the ChildCount in the Folder facet to determine if a directory was empty or not. However this seems to be unreliable, or updated asynchronously which meant that `rclone rmdir` sometimes deleted directories that had files in. This problem was spotted by the integration tests. Listing the directory instead of relying on the ChildCount fixes the problem and the integration tests, without changing the cost (one http transaction).
This commit is contained in:
parent
d49ba652e2
commit
b4d86d5450
1 changed files with 11 additions and 9 deletions
|
@ -718,15 +718,17 @@ func (f *Fs) purgeCheck(dir string, check bool) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
item, _, err := f.readMetaDataForPath(root)
|
||||
if check {
|
||||
// check to see if there are any items
|
||||
found, err := f.listAll(rootID, false, false, func(item *api.Item) bool {
|
||||
return true
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if item.Folder == nil {
|
||||
return errors.New("not a folder")
|
||||
if found {
|
||||
return fs.ErrorDirectoryNotEmpty
|
||||
}
|
||||
if check && item.Folder.ChildCount != 0 {
|
||||
return errors.New("folder not empty")
|
||||
}
|
||||
err = f.deleteObject(rootID)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue