Skip to content

Commit

Permalink
Update PR
Browse files Browse the repository at this point in the history
* Update PR
  • Loading branch information
abraunegg committed Oct 17, 2023
1 parent 6db484c commit 75c071e
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 74 deletions.
15 changes: 11 additions & 4 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,8 @@ class ApplicationConfig {

if (key == "skip_file") {
skip_file_present = true;
if (c.front.dup != getValueString("skip_file")) {
string computedBackupSkipFile = defaultSkipFile ~ "|" ~ to!string(c.front.dup);
if (computedBackupSkipFile != getValueString("skip_file")) {
log.vdebug(key, configOptionModifiedMessage);
configFileOptionsDifferent = true;
}
Expand Down Expand Up @@ -1991,9 +1992,15 @@ class ApplicationConfig {
operationalConflictDetected = true;
}

// --monitor and --download-only cannot be used together
if ((getValueBool("monitor")) && (getValueBool("download_only"))) {
log.error("ERROR: --monitor and --download-only cannot be used together.");
// --monitor and --display-sync-status cannot be used together
if ( (getValueBool("monitor")) && (getValueBool("display_sync_status"))) {
log.error("ERROR: --monitor and --display-sync-status cannot be used together.");
operationalConflictDetected = true;
}

// --sync and and --display-sync-status cannot be used together
if ((getValueBool("synchronize")) && (getValueBool("display_sync_status"))) {
log.error("ERROR: --sync and and --display-sync-status cannot be used together.");
operationalConflictDetected = true;
}

Expand Down
47 changes: 29 additions & 18 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,12 @@ int main(string[] cliArgs) {

// Start the monitor process
log.log("OneDrive synchronisation interval (seconds): ", appConfig.getValueLong("monitor_interval"));
log.vlog("Maximum allowed open files: ", maxOpenFiles);
log.vlog("Maximum allowed inotify user watches: ", maxInotifyWatches);

// If we are in a --download-only method of operation, the output of these is not required
if (!appConfig.getValueBool("download_only")) {
log.vlog("Maximum allowed open files: ", maxOpenFiles);
log.vlog("Maximum allowed inotify user watches: ", maxInotifyWatches);
}

// Configure the monitor class
Monitor filesystemMonitor = new Monitor(appConfig, selectiveSync);
Expand All @@ -616,7 +620,7 @@ int main(string[] cliArgs) {
filesystemMonitor.onFileChanged = delegate(string path) {
log.vlog("[M] Local file changed: ", path);
try {
syncEngineInstance.scanLocalFilesystemPathForNewData(dirName(path));
syncEngineInstance.handleLocalFileTrigger(path);
} catch (CurlException e) {
log.vlog("Offline, cannot upload changed item!");
} catch(Exception e) {
Expand Down Expand Up @@ -665,15 +669,19 @@ int main(string[] cliArgs) {
signal(SIGINT, &exitHandler);
signal(SIGTERM, &exitHandler);

// Initialise the filesystem monitor class
try {
log.log("Initialising filesystem inotify monitoring ...");
filesystemMonitor.initialise();
log.log("Performing initial syncronisation to ensure consistent local state ...");
} catch (MonitorException e) {
// monitor class initialisation failed
log.error("ERROR: ", e.msg);
return EXIT_FAILURE;
// Initialise the local filesystem monitor class using inotify to monitor for local filesystem changes
// If we are in a --download-only method of operation, we do not enable local filesystem monitoring
if (!appConfig.getValueBool("download_only")) {
// Not using --download-only
try {
log.log("Initialising filesystem inotify monitoring ...");
filesystemMonitor.initialise();
log.log("Performing initial syncronisation to ensure consistent local state ...");
} catch (MonitorException e) {
// monitor class initialisation failed
log.error("ERROR: ", e.msg);
return EXIT_FAILURE;
}
}

// Filesystem monitor loop
Expand All @@ -695,12 +703,15 @@ int main(string[] cliArgs) {
// Do we need to validate the runtimeSyncDirectory to check for the presence of a '.nosync' file - the disk may have been ejected ..
checkForNoMountScenario();

try {
// Process any inotify events
filesystemMonitor.update(true);
} catch (MonitorException e) {
// Catch any exceptions thrown by inotify / monitor engine
log.error("ERROR: The following inotify error was generated: ", e.msg);
// If we are in a --download-only method of operation, there is no filesystem monitoring, so no inotify events to check
if (!appConfig.getValueBool("download_only")) {
try {
// Process any inotify events
filesystemMonitor.update(true);
} catch (MonitorException e) {
// Catch any exceptions thrown by inotify / monitor engine
log.error("ERROR: The following inotify error was generated: ", e.msg);
}
}

// Check for notifications pushed from Microsoft to the webhook
Expand Down
6 changes: 5 additions & 1 deletion src/onedrive.d
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,11 @@ class OneDriveApi {
private void checkAccessTokenExpired() {
try {
if (Clock.currTime() >= appConfig.accessTokenExpiration) {
log.vdebug("Microsoft OneDrive Access Token has EXPIRED. Must generate a new Microsoft OneDrive Access Token");
newToken();
}
} else {
log.vdebug("Existing Microsoft OneDrive Access Token Expires: ", appConfig.accessTokenExpiration);
}
} catch (OneDriveException e) {
if (e.httpStatusCode == 400 || e.httpStatusCode == 401) {
// flag error and notify
Expand Down Expand Up @@ -1034,6 +1037,7 @@ class OneDriveApi {
}

private void newToken() {
log.vdebug("Need to generate a new access token for Microsoft OneDrive");
string postData =
"client_id=" ~ clientId ~
"&redirect_uri=" ~ redirectUrl ~
Expand Down
Loading

0 comments on commit 75c071e

Please sign in to comment.