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