mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-23 16:12:12 +02:00
Implement recursive deletion when Retention Policy is enabled (#955)
* Implement recursive deletion when Retention Policy is enabled
This commit is contained in:
parent
9e020f05cc
commit
3b85d574e0
46
src/sync.d
46
src/sync.d
|
@ -3948,15 +3948,8 @@ final class SyncEngine
|
||||||
bool flagAsBigDelete = false;
|
bool flagAsBigDelete = false;
|
||||||
|
|
||||||
// query the database - how many objects will this remove?
|
// query the database - how many objects will this remove?
|
||||||
long itemsToDelete = 0;
|
auto children = getChildren(item.driveId, item.id);
|
||||||
auto children = itemdb.selectChildren(item.driveId, item.id);
|
long itemsToDelete = count(children);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
// 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")) {
|
if (!cfg.getValueBool("monitor")) {
|
||||||
|
@ -4000,11 +3993,18 @@ final class SyncEngine
|
||||||
JSONValue errorMessage = parseJSON(replace(e.msg, errorArray[0], ""));
|
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") {
|
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
|
// 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
|
try {
|
||||||
// WARN:
|
foreach_reverse (Item child; children) {
|
||||||
log.error("\nERROR: Unable to delete the requested remote path from OneDrive: ", path);
|
onedrive.deleteById(child.driveId, child.id, child.eTag);
|
||||||
log.error("ERROR: This error is due to OneDrive Business Retention Policy being applied");
|
// delete the child reference in the local database
|
||||||
log.error("WORKAROUND: Manually delete all files and folders from the above path as per Business Retention Policy\n");
|
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 {
|
} else {
|
||||||
// Not a 403 response & OneDrive Business Account / O365 Shared Folder / Library
|
// 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){
|
private Item[] getChildren(string driveId, string id){
|
||||||
// count children
|
Item[] children;
|
||||||
long childrenCount = 0;
|
children ~= itemdb.selectChildren(driveId, id);
|
||||||
auto children = itemdb.selectChildren(driveId, id);
|
foreach (Item child; children) {
|
||||||
childrenCount = count(children);
|
|
||||||
foreach (Item child; children) {
|
|
||||||
if (child.type != ItemType.file) {
|
if (child.type != ItemType.file) {
|
||||||
// recursively count the children of this child
|
// recursively get the children of this child
|
||||||
childrenCount = childrenCount + countChildren(child.driveId, child.id);
|
children ~= getChildren(child.driveId, child.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return childrenCount;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the item's last modified time
|
// update the item's last modified time
|
||||||
|
|
Loading…
Reference in a new issue