Skip to content

Commit 5d660c3

Browse files
authored
Fix OneDrive Personal Shared Folder removal issue (#3147)
* When removing the a OneDrive Personal Shared Folder locally, ensure we are only removing our 'link' to the folder, not the entire folder from the remote user * Ensure the 'root' object is removed for the Shared Folder if there are no other 'children' for that Shared Folder parent.
1 parent e588967 commit 5d660c3

File tree

1 file changed

+54
-21
lines changed

1 file changed

+54
-21
lines changed

src/sync.d

+54-21
Original file line numberDiff line numberDiff line change
@@ -8745,35 +8745,59 @@ class SyncEngine {
87458745
Item actualItemToDelete;
87468746
Item remoteShortcutLinkItem;
87478747

8748+
// OneDrive Shared Folder Link Handling
8749+
// - If the item to delete is on a remote drive ... technically we do not own this and should not be deleting this online
8750+
// We should however be deleting the 'link' in our account online, and, remove the DB link entries (root / folder DB Tie records)
8751+
bool businessSharingEnabled = false;
8752+
87488753
// OneDrive Business Shared Folder Deletion Handling
87498754
// Is this a Business Account with Sync Business Shared Items enabled?
87508755
if ((appConfig.accountType == "business") && (appConfig.getValueBool("sync_business_shared_items"))) {
87518756
// Syncing Business Shared Items is enabled
8757+
businessSharingEnabled = true;
8758+
}
8759+
8760+
// Is this a 'personal' account type or is this a Business Account with Sync Business Shared Items enabled?
8761+
if ((appConfig.accountType == "personal") || businessSharingEnabled) {
8762+
// Personal account type or syncing Business Shared Items is enabled
8763+
// Is the 'drive' where this is to be deleted on 'our' drive or is this a remote 'drive' ?
87528764
if (itemToDelete.driveId != appConfig.defaultDriveId) {
8753-
// The item to delete is on a remote drive ... technically we do not own this and should not be deleting this online
8754-
// We should however be deleting the 'link' in our account online, and, remove the DB link entry
8755-
if (itemToDelete.type == ItemType.dir) {
8756-
// Query the database for this potential link
8757-
itemDB.selectByPathIncludingRemoteItems(path, appConfig.defaultDriveId, remoteShortcutLinkItem);
8765+
// The item to delete is on a remote drive ... this must be handled in a specific way
8766+
if (itemToDelete.type == ItemType.dir) {
8767+
// Select the 'remote' database object type using these details
8768+
// Get the DB entry for this 'remote' item
8769+
itemDB.selectRemoteTypeByRemoteDriveId(itemToDelete.driveId, itemToDelete.id, remoteShortcutLinkItem);
8770+
}
8771+
}
8772+
8773+
// We potentially now have the correct details to delete in our account
8774+
if (remoteShortcutLinkItem.type == ItemType.remote) {
8775+
// A valid 'remote' DB entry was returned
8776+
if (debugLogging) {addLogEntry("remoteShortcutLinkItem: " ~ to!string(remoteShortcutLinkItem), ["debug"]);}
8777+
// Set actualItemToDelete to this data
8778+
actualItemToDelete = remoteShortcutLinkItem;
8779+
8780+
// Delete the shortcut reference in the local database
8781+
if (appConfig.accountType == "personal") {
8782+
// Personal Shared Folder deletion message
8783+
if (debugLogging) {addLogEntry("Deleted OneDrive Personal Shared Folder 'Shortcut Link'", ["debug"]);}
8784+
} else {
8785+
// Business Shared Folder deletion message
8786+
if (debugLogging) {addLogEntry("Deleted OneDrive Business Shared Folder 'Shortcut Link'", ["debug"]);}
87588787
}
8788+
8789+
// Perform action deletion from database
8790+
itemDB.deleteById(remoteShortcutLinkItem.driveId, remoteShortcutLinkItem.id);
8791+
} else {
8792+
// No data was returned, use the original data
8793+
actualItemToDelete = itemToDelete;
87598794
}
8760-
}
8761-
8762-
// Configure actualItemToDelete
8763-
if (remoteShortcutLinkItem.id != "") {
8764-
// A DB entry was returned
8765-
if (debugLogging) {addLogEntry("remoteShortcutLinkItem: " ~ to!string(remoteShortcutLinkItem), ["debug"]);}
8766-
// Set actualItemToDelete to this data
8767-
actualItemToDelete = remoteShortcutLinkItem;
8768-
// Delete the shortcut reference in the local database
8769-
itemDB.deleteById(remoteShortcutLinkItem.driveId, remoteShortcutLinkItem.id);
8770-
if (debugLogging) {addLogEntry("Deleted OneDrive Business Shared Folder 'Shortcut Link'", ["debug"]);}
87718795
} else {
8772-
// No data was returned, use the original data
8796+
// Set actualItemToDelete to original data
87738797
actualItemToDelete = itemToDelete;
87748798
}
87758799

8776-
// Try the online deletion
8800+
// Try the online deletion using the 'actualItemToDelete' values
87778801
try {
87788802
// Create new OneDrive API Instance
87798803
uploadDeletedItemOneDriveApiInstance = new OneDriveApi(appConfig);
@@ -8808,9 +8832,18 @@ class SyncEngine {
88088832

88098833
// Delete the reference in the local database - use the original input
88108834
itemDB.deleteById(itemToDelete.driveId, itemToDelete.id);
8811-
if (itemToDelete.remoteId != null) {
8812-
// If the item is a remote item, delete the reference in the local database
8813-
itemDB.deleteById(itemToDelete.remoteDriveId, itemToDelete.remoteId);
8835+
8836+
// Was the original item a 'Shared Folder' ?
8837+
if (remoteShortcutLinkItem.type == ItemType.remote) {
8838+
// Are there any other 'children' for itemToDelete parent ... this parent may have other Shared Folders added to our account that we have not removed ..
8839+
Item[] remainingChildren;
8840+
remainingChildren ~= itemDB.selectChildren(itemToDelete.driveId, itemToDelete.parentId);
8841+
8842+
// Only if there are zero children for this parent item, remove the 'root' record
8843+
if (count(remainingChildren) == 0) {
8844+
// No more children for this parental object
8845+
itemDB.deleteById(itemToDelete.driveId, itemToDelete.parentId);
8846+
}
88148847
}
88158848
} else {
88168849
// log that this is a dry-run activity

0 commit comments

Comments
 (0)