Skip to content

Commit

Permalink
Fix Issue #2883 where creating a new folder online generates an excep…
Browse files Browse the repository at this point in the history
…tion as it is in a Shared Online Folder (#2895)

* Fix issue when attempting to create a new folder online, but this is in a Shared Folder, and 'sync_business_shared_items' is not being used
* Add same check to ensure that if this is a Business Account and an online shared folder, 'sync_business_shared_items' needs to be enabled when using --single-directory flag
  • Loading branch information
abraunegg authored Oct 9, 2024
1 parent 8930cbe commit 52cd0af
Showing 1 changed file with 73 additions and 11 deletions.
84 changes: 73 additions & 11 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -773,17 +773,26 @@ class SyncEngine {
// Is this item a potential Shared Folder?
// Is this JSON a remote object
if (isItemRemote(onlinePathData)) {
// The path we are seeking is remote to our account drive id
searchItem.driveId = onlinePathData["remoteItem"]["parentReference"]["driveId"].str;
searchItem.id = onlinePathData["remoteItem"]["id"].str;
// Is this a Personal Account Type or has 'sync_business_shared_items' been enabled?
if ((appConfig.accountType == "personal") || (appConfig.getValueBool("sync_business_shared_items"))) {
// The path we are seeking is remote to our account drive id
searchItem.driveId = onlinePathData["remoteItem"]["parentReference"]["driveId"].str;
searchItem.id = onlinePathData["remoteItem"]["id"].str;
} else {
// This is a shared folder location, but we are not a 'personal' account, and 'sync_business_shared_items' has not been enabled
addLogEntry();
addLogEntry("ERROR: The requested --single-directory path to sync is a Shared Folder online and 'sync_business_shared_items' is not enabled");
addLogEntry();
forceExit();
}
}

// Set these items so that these can be used as required
singleDirectoryScopeDriveId = searchItem.driveId;
singleDirectoryScopeItemId = searchItem.id;
} else {
addLogEntry();
addLogEntry("The requested --single-directory path to sync has generated an error. Please correct this error and try again.");
addLogEntry("ERROR: The requested --single-directory path to sync has generated an error. Please correct this error and try again.");
addLogEntry();
forceExit();
}
Expand Down Expand Up @@ -5241,11 +5250,19 @@ class SyncEngine {
if (parentItem.type == ItemType.remote) {
// This folder is a potential shared object
if (debugLogging) {addLogEntry("ParentItem is a remote item object", ["debug"]);}
// Need to create the DB Tie for this shared object to ensure this exists in the database
createDatabaseTieRecordForOnlineSharedFolder(parentItem);
// Update the queryItem values
queryItem.driveId = parentItem.remoteDriveId;
queryItem.id = parentItem.remoteId;

// Is this a Personal Account Type or has 'sync_business_shared_items' been enabled?
if ((appConfig.accountType == "personal") || (appConfig.getValueBool("sync_business_shared_items"))) {
// Need to create the DB Tie for this shared object to ensure this exists in the database
createDatabaseTieRecordForOnlineSharedFolder(parentItem);
// Update the queryItem values
queryItem.driveId = parentItem.remoteDriveId;
queryItem.id = parentItem.remoteId;
} else {
// This is a shared folder location, but we are not a 'personal' account, and 'sync_business_shared_items' has not been enabled
addLogEntry("ERROR: Unable to create directory online as 'sync_business_shared_items' is not enabled");
return;
}
} else {
// Use parent item for the query item
if (debugLogging) {addLogEntry("Standard Query, use parentItem", ["debug"]);}
Expand Down Expand Up @@ -8932,8 +8949,53 @@ class SyncEngine {
Item[] rootDriveItems;
Item dbRecord;
rootDriveItems = itemDB.selectByDriveId(parentItem.remoteDriveId);
dbRecord = rootDriveItems[0];
tieDBItem.parentId = dbRecord.id;

// Fix Issue #2883
if (rootDriveItems.length > 0) {
// Use the first record returned
dbRecord = rootDriveItems[0];
tieDBItem.parentId = dbRecord.id;
} else {
// Business Account ... but itemDB.selectByDriveId returned no entries ... need to query for this item online to get the correct details given they are not in the database
if (debugLogging) {addLogEntry("itemDB.selectByDriveId(parentItem.remoteDriveId) returned zero database entries for this remoteDriveId: " ~ to!string(parentItem.remoteDriveId), ["debug"]);}

// Create a new API Instance for this query and initialise it
OneDriveApi getPathDetailsApiInstance;
JSONValue latestOnlineDetails;
getPathDetailsApiInstance = new OneDriveApi(appConfig);
getPathDetailsApiInstance.initialise();

try {
// Get the latest online details
latestOnlineDetails = getPathDetailsApiInstance.getPathDetailsById(parentItem.remoteDriveId, parentItem.remoteId);
if (debugLogging) {addLogEntry("Parent JSON details from Online Query: " ~ to!string(latestOnlineDetails), ["debug"]);}

// Convert JSON to a database compatible item
Item tempOnlineRecord = makeItem(latestOnlineDetails);

// Configure tieDBItem.parentId to use tempOnlineRecord.id
tieDBItem.parentId = tempOnlineRecord.id;

// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
getPathDetailsApiInstance.releaseCurlEngine();
getPathDetailsApiInstance = null;
// Perform Garbage Collection
GC.collect();

} catch (OneDriveException e) {
// Display error message
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));

// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
getPathDetailsApiInstance.releaseCurlEngine();
getPathDetailsApiInstance = null;
// Perform Garbage Collection
GC.collect();
return;
}
}

// Free the array memory
rootDriveItems = [];
}

Expand Down

0 comments on commit 52cd0af

Please sign in to comment.