diff --git a/src/config.d b/src/config.d index c25583c6..32acba34 100644 --- a/src/config.d +++ b/src/config.d @@ -45,6 +45,8 @@ final class Config longValues["verbose"] = 0; longValues["monitor_interval"] = 45, longValues["min_notif_changes"] = 5; + longValues["min_notif_changes"] = 5; + longValues["monitor_log_frequency"] = 5; // Determine the users home directory. // Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts @@ -200,6 +202,9 @@ final class Config "monitor|m", "Keep monitoring for local and remote changes", &boolValues["monitor"], + "monitor-log-frequency", + "Frequency of logging in monitor mode", + &longValues["monitor_log_frequency"], "no-remote-delete", "Do not delete local file 'deletes' from OneDrive when using --upload-only", &boolValues["no_remote_delete"], diff --git a/src/main.d b/src/main.d index ca1508f4..a7236d38 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 @@ -328,7 +332,7 @@ int main(string[] args) } // Perform the sync - performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), cfg.getValueBool("monitor")); + performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), LOG_NORMAL); } } @@ -389,11 +393,16 @@ int main(string[] args) if (!cfg.getValueBool("download_only")) m.init(cfg, cfg.getValueLong("verbose") > 0, cfg.getValueBool("skip_symlinks")); // monitor loop immutable auto checkInterval = dur!"seconds"(cfg.getValueLong("monitor_interval")); + immutable auto logInterval = cfg.getValueLong("monitor_log_frequency"); auto lastCheckTime = MonoTime.currTime(); + auto logMonitorCounter = 0; while (true) { if (!cfg.getValueBool("download_only")) 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); @@ -404,7 +413,7 @@ int main(string[] args) return EXIT_FAILURE; } try { - performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), cfg.getValueBool("monitor")); + performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), (logMonitorCounter == logInterval ? MONITOR_LOG_QUIET : MONITOR_LOG_SILENT)); if (!cfg.getValueBool("download_only")) { // discard all events that may have been generated by the sync m.update(false); @@ -413,7 +422,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) { @@ -452,7 +461,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 = "/"; @@ -472,18 +481,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) { @@ -498,18 +507,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) { diff --git a/src/sync.d b/src/sync.d index 35075bbc..4b0937e1 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();