Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #2883 where creating a new folder online generates an exception as it is in a Shared Online Folder #2895

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading