Implement recursive deletion when Retention Policy is enabled (#955)

* Implement recursive deletion when Retention Policy is enabled
This commit is contained in:
Christian Ponte-Fernández 2020-06-16 22:49:43 +02:00 committed by GitHub
parent 9e020f05cc
commit 3b85d574e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3948,15 +3948,8 @@ final class SyncEngine
bool flagAsBigDelete = false;
// query the database - how many objects will this remove?
long itemsToDelete = 0;
auto children = itemdb.selectChildren(item.driveId, item.id);
itemsToDelete = count(children);
foreach (Item child; children) {
if (child.type != ItemType.file) {
// recursively count the children of this child
itemsToDelete = itemsToDelete + countChildren(child.driveId, child.id);
}
}
auto children = getChildren(item.driveId, item.id);
long itemsToDelete = count(children);
// Are we running in monitor mode? A local delete of a file will issue a inotify event, which will trigger the local & remote data immediately
if (!cfg.getValueBool("monitor")) {
@ -4000,11 +3993,18 @@ final class SyncEngine
JSONValue errorMessage = parseJSON(replace(e.msg, errorArray[0], ""));
if (errorMessage["error"]["message"].str == "Request was cancelled by event received. If attempting to delete a non-empty folder, it's possible that it's on hold") {
// Issue #338 - Unable to delete OneDrive content when OneDrive Business Retention Policy is enabled
// TODO: We have to recursively delete all files & folders from this path to delete
// WARN:
log.error("\nERROR: Unable to delete the requested remote path from OneDrive: ", path);
log.error("ERROR: This error is due to OneDrive Business Retention Policy being applied");
log.error("WORKAROUND: Manually delete all files and folders from the above path as per Business Retention Policy\n");
try {
foreach_reverse (Item child; children) {
onedrive.deleteById(child.driveId, child.id, child.eTag);
// delete the child reference in the local database
itemdb.deleteById(child.driveId, child.id);
}
onedrive.deleteById(item.driveId, item.id, item.eTag);
} catch (OneDriveException e) {
// display what the error is
displayOneDriveErrorMessage(e.msg);
return;
}
}
} else {
// Not a 403 response & OneDrive Business Account / O365 Shared Folder / Library
@ -4023,19 +4023,17 @@ final class SyncEngine
}
}
}
private long countChildren(string driveId, string id){
// count children
long childrenCount = 0;
auto children = itemdb.selectChildren(driveId, id);
childrenCount = count(children);
foreach (Item child; children) {
private Item[] getChildren(string driveId, string id){
Item[] children;
children ~= itemdb.selectChildren(driveId, id);
foreach (Item child; children) {
if (child.type != ItemType.file) {
// recursively count the children of this child
childrenCount = childrenCount + countChildren(child.driveId, child.id);
// recursively get the children of this child
children ~= getChildren(child.driveId, child.id);
}
}
return childrenCount;
return children;
}
// update the item's last modified time