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

Potential fix for #2941 #2943

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
65 changes: 55 additions & 10 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ class SyncEngine {
// Control whether the worker threads are daemon threads. A daemon thread is automatically terminated when all non-daemon threads have terminated.
processPool.isDaemon(true); // daemon thread

// Flag for 'no-sync' task
bool noSyncTask = false;

// Create a new instance of the OneDrive API
OneDriveApi oneDriveApiInstance;
oneDriveApiInstance = new OneDriveApi(appConfig);
Expand All @@ -337,16 +340,30 @@ class SyncEngine {
oneDriveApiInstance = null;
}

// Issue #2941
// If the account being used _only_ has access to specific resources, getDefaultDriveDetails() will generate problems and cause
// the application to exit, which, is technically the right thing to do (no access to account details) ... but if:
// - are we doing a no-sync task ?
// - do we have the 'drive_id' via config file ?
// Are we not doing a --sync or a --monitor operation? Both of these will be false if they are not set
if ((!appConfig.getValueBool("synchronize")) && (!appConfig.getValueBool("monitor"))) {
// set flag
noSyncTask = true;
}

// Can the API be initialised successfully?
if (oneDriveApiInstance.initialise()) {
// Get the relevant default drive details
try {
getDefaultDriveDetails();
} catch (AccountDetailsException exception) {
// details could not be queried
addLogEntry(exception.msg);
// Must force exit here, allow logging to be done
forceExit();
// was this a no-sync task?
if (!noSyncTask) {
// details could not be queried
addLogEntry(exception.msg);
// Must force exit here, allow logging to be done
forceExit();
}
}

// Get the relevant default root details
Expand All @@ -359,11 +376,11 @@ class SyncEngine {
forceExit();
}

// Display details
// Display relevant account details
try {
displaySyncEngineDetails();
} catch (AccountDetailsException exception) {
// Details could not be queried
// details could not be queried
addLogEntry(exception.msg);
// Must force exit here, allow logging to be done
forceExit();
Expand Down Expand Up @@ -403,12 +420,19 @@ class SyncEngine {

// Function variables
JSONValue defaultOneDriveDriveDetails;
bool noSyncTask = false;

// Create a new instance of the OneDrive API
OneDriveApi getDefaultDriveApiInstance;
getDefaultDriveApiInstance = new OneDriveApi(appConfig);
getDefaultDriveApiInstance.initialise();

// Are we not doing a --sync or a --monitor operation? Both of these will be false if they are not set
if ((!appConfig.getValueBool("synchronize")) && (!appConfig.getValueBool("monitor"))) {
// set flag
noSyncTask = true;
}

// Get Default Drive Details for this Account
try {
if (debugLogging) {addLogEntry("Getting Account Default Drive Details", ["debug"]);}
Expand Down Expand Up @@ -463,8 +487,19 @@ class SyncEngine {
addLogEntry("cachedOnlineDriveData.quotaRestricted = " ~ to!string(cachedOnlineDriveData.quotaRestricted), ["debug"]);
}
} else {
// Handle the invalid JSON response
throw new AccountDetailsException();
// Did the configuration file contain a 'drive_id' entry
// If this exists, this will be a 'documentLibrary'
if (appConfig.getValueString("drive_id").length) {
// Force set these as for whatever reason we could to query these via the getDefaultDriveDetails API call
appConfig.accountType = "documentLibrary";
appConfig.defaultDriveId = appConfig.getValueString("drive_id");
} else {
// was this a no-sync task?
if (!noSyncTask) {
// Handle the invalid JSON response by throwing an exception error
throw new AccountDetailsException();
}
}
}

// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
Expand All @@ -479,12 +514,19 @@ class SyncEngine {

// Function variables
JSONValue defaultOneDriveRootDetails;
bool noSyncTask = false;

// Create a new instance of the OneDrive API
OneDriveApi getDefaultRootApiInstance;
getDefaultRootApiInstance = new OneDriveApi(appConfig);
getDefaultRootApiInstance.initialise();

// Are we not doing a --sync or a --monitor operation? Both of these will be false if they are not set
if ((!appConfig.getValueBool("synchronize")) && (!appConfig.getValueBool("monitor"))) {
// set flag
noSyncTask = true;
}

// Get Default Root Details for this Account
try {
if (debugLogging) {addLogEntry("Getting Account Default Root Details", ["debug"]);}
Expand Down Expand Up @@ -513,8 +555,11 @@ class SyncEngine {
// Save the item to the database, so the account root drive is is always going to be present in the DB
saveItem(defaultOneDriveRootDetails);
} else {
// Handle the invalid JSON response
throw new AccountDetailsException();
// was this a no-sync task?
if (!noSyncTask) {
// Handle the invalid JSON response by throwing an exception error
throw new AccountDetailsException();
}
}

// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
Expand Down
Loading