From b668ecef71d7643b62285aec345e33a859b9ecba Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 27 Feb 2019 04:49:23 +0900 Subject: [PATCH 1/2] Create new upload session on reinit (Issue: #379) (#392) * By moving the UploadSession creation from the constructor to the init function we guarantee that a re-initialization also starts a new UploadSession. --- src/main.d | 2 +- src/sync.d | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.d b/src/main.d index 6bc0c112..d2819be2 100644 --- a/src/main.d +++ b/src/main.d @@ -577,7 +577,7 @@ int main(string[] args) // we already tried three times in the performSync routine // if we still have problems, then the sync handle might have // gone stale and we need to re-initialize the sync engine - log.log("Pesistent connection errors, reinitializing connection"); + log.log("Persistent connection errors, reinitializing connection"); sync.reset(); } } catch (CurlException e) { diff --git a/src/sync.d b/src/sync.d index 05e93501..557b1714 100644 --- a/src/sync.d +++ b/src/sync.d @@ -208,7 +208,7 @@ final class SyncEngine this.onedrive = onedrive; this.itemdb = itemdb; this.selectiveSync = selectiveSync; - session = UploadSession(onedrive, cfg.uploadStateFilePath); + // session = UploadSession(onedrive, cfg.uploadStateFilePath); } void reset() @@ -226,6 +226,8 @@ final class SyncEngine return; } + session = UploadSession(onedrive, cfg.uploadStateFilePath); + // Need to catch 400 or 5xx server side errors at initialization try { oneDriveDetails = onedrive.getDefaultDrive(); From 09f328e63f728aea7f20cfc8cbf74f833ae79f26 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 27 Feb 2019 05:21:23 +0900 Subject: [PATCH 2/2] configurable logging intervals in monitor mode (Issue: #378) (#391) * Configurable interval of logging in monitor mode (Issue: #378) --- src/config.d | 2 ++ src/main.d | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/config.d b/src/config.d index a6e37243..ee89fc79 100644 --- a/src/config.d +++ b/src/config.d @@ -45,6 +45,8 @@ final class Config setValue("drive_id", ""); // Minimal changes that trigger a log and notification on sync setValue("min_notif_changes", "5"); + // Frequency of log messages in monitor, ie after n sync runs ship out a log message + setValue("monitor_log_frequency", "5"); if (!load(userConfigFilePath)) { // What was the reason for failure? diff --git a/src/main.d b/src/main.d index d2819be2..12ab3877 100644 --- a/src/main.d +++ b/src/main.d @@ -10,6 +10,10 @@ static import log; OneDriveApi oneDrive; ItemDatabase itemDb; +enum MONITOR_LOG_SILENT = 2; +enum MONITOR_LOG_QUIET = 1; +enum LOG_NORMAL = 0; + int main(string[] args) { // Disable buffering on stdout @@ -491,7 +495,7 @@ int main(string[] args) } // Perform the sync - performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, monitor); + performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, LOG_NORMAL); } } @@ -553,11 +557,16 @@ int main(string[] args) if (!downloadOnly) m.init(cfg, verbose, skipSymlinks); // monitor loop immutable auto checkInterval = dur!"seconds"(to!long(cfg.getValue("monitor_interval"))); + immutable auto logInterval = to!long(cfg.getValue("monitor_log_frequency")); auto lastCheckTime = MonoTime.currTime(); + auto logMonitorCounter = 0; while (true) { if (!downloadOnly) m.update(online); auto currTime = MonoTime.currTime(); if (currTime - lastCheckTime > checkInterval) { + logMonitorCounter += 1; + if (logMonitorCounter > logInterval) + logMonitorCounter = 1; // log.logAndNotify("DEBUG trying to create checkpoint"); // auto res = itemdb.db_checkpoint(); // log.logAndNotify("Checkpoint return: ", res); @@ -568,7 +577,7 @@ int main(string[] args) return EXIT_FAILURE; } try { - performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, monitor); + performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, (logMonitorCounter == logInterval ? MONITOR_LOG_QUIET : MONITOR_LOG_SILENT)); if (!downloadOnly) { // discard all events that may have been generated by the sync m.update(false); @@ -616,7 +625,7 @@ bool initSyncEngine(SyncEngine sync) } // try to synchronize the folder three times -void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, bool localFirst, bool uploadOnly, bool monitor) +void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, bool localFirst, bool uploadOnly, long logLevel) { int count; string remotePath = "/"; @@ -636,18 +645,18 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo log.vlog("Syncing changes from this selected path: ", singleDirectory); if (uploadOnly){ // Upload Only of selected single directory - if (!monitor) log.log("Syncing changes from selected local path only - NOT syncing data changes from OneDrive ..."); + if (logLevel < MONITOR_LOG_QUIET) log.log("Syncing changes from selected local path only - NOT syncing data changes from OneDrive ..."); sync.scanForDifferences(localPath); } else { // No upload only if (localFirst) { // Local First - if (!monitor) log.log("Syncing changes from selected local path first before downloading changes from OneDrive ..."); + if (logLevel < MONITOR_LOG_QUIET) log.log("Syncing changes from selected local path first before downloading changes from OneDrive ..."); sync.scanForDifferences(localPath); sync.applyDifferencesSingleDirectory(remotePath); } else { // OneDrive First - if (!monitor) log.log("Syncing changes from selected OneDrive path ..."); + if (logLevel < MONITOR_LOG_QUIET) log.log("Syncing changes from selected OneDrive path ..."); sync.applyDifferencesSingleDirectory(remotePath); // is this a download only request? if (!downloadOnly) { @@ -662,18 +671,18 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo // no single directory sync if (uploadOnly){ // Upload Only of entire sync_dir - if (!monitor) log.log("Syncing changes from local path only - NOT syncing data changes from OneDrive ..."); + if (logLevel < MONITOR_LOG_QUIET) log.log("Syncing changes from local path only - NOT syncing data changes from OneDrive ..."); sync.scanForDifferences(localPath); } else { // No upload only if (localFirst) { // sync local files first before downloading from OneDrive - if (!monitor) log.log("Syncing changes from local path first before downloading changes from OneDrive ..."); + if (logLevel < MONITOR_LOG_QUIET) log.log("Syncing changes from local path first before downloading changes from OneDrive ..."); sync.scanForDifferences(localPath); sync.applyDifferences(); } else { // sync from OneDrive first before uploading files to OneDrive - log.log("Syncing changes from OneDrive ..."); + if (logLevel < MONITOR_LOG_SILENT) log.log("Syncing changes from OneDrive ..."); sync.applyDifferences(); // is this a download only request? if (!downloadOnly) {