@@ -8745,35 +8745,59 @@ class SyncEngine {
8745
8745
Item actualItemToDelete;
8746
8746
Item remoteShortcutLinkItem;
8747
8747
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
+
8748
8753
// OneDrive Business Shared Folder Deletion Handling
8749
8754
// Is this a Business Account with Sync Business Shared Items enabled?
8750
8755
if ((appConfig.accountType == "business") && (appConfig.getValueBool("sync_business_shared_items"))) {
8751
8756
// 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' ?
8752
8764
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"]);}
8758
8787
}
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;
8759
8794
}
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"]);}
8771
8795
} else {
8772
- // No data was returned, use the original data
8796
+ // Set actualItemToDelete to original data
8773
8797
actualItemToDelete = itemToDelete;
8774
8798
}
8775
8799
8776
- // Try the online deletion
8800
+ // Try the online deletion using the 'actualItemToDelete' values
8777
8801
try {
8778
8802
// Create new OneDrive API Instance
8779
8803
uploadDeletedItemOneDriveApiInstance = new OneDriveApi(appConfig);
@@ -8808,9 +8832,18 @@ class SyncEngine {
8808
8832
8809
8833
// Delete the reference in the local database - use the original input
8810
8834
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
+ }
8814
8847
}
8815
8848
} else {
8816
8849
// log that this is a dry-run activity
0 commit comments