Resolve 'Directory not empty' issues on bulk deletes

* In some cases OneDrive does not send all delete changes or changes are
out of order. When deleting local files, this can lead to a 'Directory
not empty' error. This change adds to check for any remaining children
of a directory that is to be deleted and delete them before
This commit is contained in:
abraunegg 2018-04-26 09:45:18 +10:00
parent 65a1181fcf
commit 6fe06d03ac

View file

@ -596,16 +596,18 @@ final class SyncEngine
itemdb.deleteById(item.remoteDriveId, item.remoteId);
}
if (exists(path)) {
// path exists on the local system
if (isFile(path)) {
remove(path);
} else {
try {
if (item.remoteDriveId == null) {
rmdir(path);
} else {
// children of remote items are not enumerated
rmdirRecurse(path);
// Remove any children of this path if they still exist
// Resolve 'Directory not empty' error when deleting local files
foreach (DirEntry child; dirEntries(path, SpanMode.depth, false)) {
attrIsDir(child.linkAttributes) ? rmdir(child.name) : remove(child.name);
}
// Remove the path now that it is empty of children
rmdirRecurse(path);
} catch (FileException e) {
log.log(e.msg);
}