Skip to content

Commit 273bcbf

Browse files
authored
Allow no-sync operations to complete online account checks (#2943)
* Allow no-sync operations to complete online account checks so that the client does not exit prematurely when account details cannot be sourced if we are performing a no-sync operation such as --get-sharepoint-drive-id This then allows errors such as the issue in #2941 to be displayed to assist in tracking down why the client is not working for these no-sync operation queries
1 parent 5dc851b commit 273bcbf

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

src/sync.d

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ class SyncEngine {
327327
// Control whether the worker threads are daemon threads. A daemon thread is automatically terminated when all non-daemon threads have terminated.
328328
processPool.isDaemon(true); // daemon thread
329329

330+
// Flag for 'no-sync' task
331+
bool noSyncTask = false;
332+
330333
// Create a new instance of the OneDrive API
331334
OneDriveApi oneDriveApiInstance;
332335
oneDriveApiInstance = new OneDriveApi(appConfig);
@@ -337,16 +340,30 @@ class SyncEngine {
337340
oneDriveApiInstance = null;
338341
}
339342

343+
// Issue #2941
344+
// If the account being used _only_ has access to specific resources, getDefaultDriveDetails() will generate problems and cause
345+
// the application to exit, which, is technically the right thing to do (no access to account details) ... but if:
346+
// - are we doing a no-sync task ?
347+
// - do we have the 'drive_id' via config file ?
348+
// Are we not doing a --sync or a --monitor operation? Both of these will be false if they are not set
349+
if ((!appConfig.getValueBool("synchronize")) && (!appConfig.getValueBool("monitor"))) {
350+
// set flag
351+
noSyncTask = true;
352+
}
353+
340354
// Can the API be initialised successfully?
341355
if (oneDriveApiInstance.initialise()) {
342356
// Get the relevant default drive details
343357
try {
344358
getDefaultDriveDetails();
345359
} catch (AccountDetailsException exception) {
346-
// details could not be queried
347-
addLogEntry(exception.msg);
348-
// Must force exit here, allow logging to be done
349-
forceExit();
360+
// was this a no-sync task?
361+
if (!noSyncTask) {
362+
// details could not be queried
363+
addLogEntry(exception.msg);
364+
// Must force exit here, allow logging to be done
365+
forceExit();
366+
}
350367
}
351368

352369
// Get the relevant default root details
@@ -359,11 +376,11 @@ class SyncEngine {
359376
forceExit();
360377
}
361378

362-
// Display details
379+
// Display relevant account details
363380
try {
364381
displaySyncEngineDetails();
365382
} catch (AccountDetailsException exception) {
366-
// Details could not be queried
383+
// details could not be queried
367384
addLogEntry(exception.msg);
368385
// Must force exit here, allow logging to be done
369386
forceExit();
@@ -403,12 +420,19 @@ class SyncEngine {
403420

404421
// Function variables
405422
JSONValue defaultOneDriveDriveDetails;
423+
bool noSyncTask = false;
406424

407425
// Create a new instance of the OneDrive API
408426
OneDriveApi getDefaultDriveApiInstance;
409427
getDefaultDriveApiInstance = new OneDriveApi(appConfig);
410428
getDefaultDriveApiInstance.initialise();
411429

430+
// Are we not doing a --sync or a --monitor operation? Both of these will be false if they are not set
431+
if ((!appConfig.getValueBool("synchronize")) && (!appConfig.getValueBool("monitor"))) {
432+
// set flag
433+
noSyncTask = true;
434+
}
435+
412436
// Get Default Drive Details for this Account
413437
try {
414438
if (debugLogging) {addLogEntry("Getting Account Default Drive Details", ["debug"]);}
@@ -463,8 +487,19 @@ class SyncEngine {
463487
addLogEntry("cachedOnlineDriveData.quotaRestricted = " ~ to!string(cachedOnlineDriveData.quotaRestricted), ["debug"]);
464488
}
465489
} else {
466-
// Handle the invalid JSON response
467-
throw new AccountDetailsException();
490+
// Did the configuration file contain a 'drive_id' entry
491+
// If this exists, this will be a 'documentLibrary'
492+
if (appConfig.getValueString("drive_id").length) {
493+
// Force set these as for whatever reason we could to query these via the getDefaultDriveDetails API call
494+
appConfig.accountType = "documentLibrary";
495+
appConfig.defaultDriveId = appConfig.getValueString("drive_id");
496+
} else {
497+
// was this a no-sync task?
498+
if (!noSyncTask) {
499+
// Handle the invalid JSON response by throwing an exception error
500+
throw new AccountDetailsException();
501+
}
502+
}
468503
}
469504

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

480515
// Function variables
481516
JSONValue defaultOneDriveRootDetails;
517+
bool noSyncTask = false;
482518

483519
// Create a new instance of the OneDrive API
484520
OneDriveApi getDefaultRootApiInstance;
485521
getDefaultRootApiInstance = new OneDriveApi(appConfig);
486522
getDefaultRootApiInstance.initialise();
487523

524+
// Are we not doing a --sync or a --monitor operation? Both of these will be false if they are not set
525+
if ((!appConfig.getValueBool("synchronize")) && (!appConfig.getValueBool("monitor"))) {
526+
// set flag
527+
noSyncTask = true;
528+
}
529+
488530
// Get Default Root Details for this Account
489531
try {
490532
if (debugLogging) {addLogEntry("Getting Account Default Root Details", ["debug"]);}
@@ -513,8 +555,11 @@ class SyncEngine {
513555
// Save the item to the database, so the account root drive is is always going to be present in the DB
514556
saveItem(defaultOneDriveRootDetails);
515557
} else {
516-
// Handle the invalid JSON response
517-
throw new AccountDetailsException();
558+
// was this a no-sync task?
559+
if (!noSyncTask) {
560+
// Handle the invalid JSON response by throwing an exception error
561+
throw new AccountDetailsException();
562+
}
518563
}
519564

520565
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory

0 commit comments

Comments
 (0)