From e922a7d85e291a3b514855804d09132f60082c65 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 8 Aug 2018 05:35:18 +1000 Subject: [PATCH] Implement Feature Request: Make checkinterval for monitor configurable (Issue #31) (#97) * Implement Feature: Make checkinterval for monitor configurable * Update monitor mode processing logic --- README.md | 8 +++++++- config | 2 ++ src/config.d | 6 +++++- src/main.d | 12 ++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 316b9bad..7f4e0365 100644 --- a/README.md +++ b/README.md @@ -228,8 +228,9 @@ This file does not get created by default, and should only be created if you wan Available options: * `sync_dir`: directory where the files will be synced -* `skip_file`: any files or directories that match this pattern will be skipped during sync. +* `skip_file`: any files or directories that match this pattern will be skipped during sync * `skip_symlinks`: any files or directories that are symlinked will be skipped during sync +* `monitor_interval`: time interval in seconds by which the monitor process will process local and remote changes ### sync_dir Example: `sync_dir="~/MyDirToSync"` @@ -251,6 +252,11 @@ Example: `skip_symlinks = "true"` Setting this to `"true"` will skip all symlinks while syncing. +### monitor_interval +Example: `monitor_interval = "300"` + +The monitor interval is defined as the wait time 'between' sync's when running in monitor mode. By default without configuration, the monitor_interval is set to 45 seconds. Setting this value to 300 will run the sync process every 5 minutes. + ### Selective sync Selective sync allows you to sync only specific files and directories. To enable selective sync create a file named `sync_list` in `~/.config/onedrive`. diff --git a/config b/config index cc4b5b5a..05e55f35 100644 --- a/config +++ b/config @@ -2,3 +2,5 @@ sync_dir = "~/OneDrive" # Skip files and directories that match this pattern skip_file = ".*|~*" +# Wait time (seconds) between sync operations in monitor mode +monitor_interval = "45" diff --git a/src/config.d b/src/config.d index 72661487..7f667545 100644 --- a/src/config.d +++ b/src/config.d @@ -33,8 +33,12 @@ final class Config // By default symlinks are not skipped (using string type // instead of boolean because hashmap only stores string types) setValue("skip_symlinks", "false"); + // Configure the monitor mode loop - the number of seconds by which + // each sync operation is undertaken when idle under monitor mode + setValue("monitor_interval", "45"); // By default we will process remote deletes - setValue("no-remote-delete", "false"); + setValue("no-remote-delete", "false"); + if (!load(userConfigFilePath)) { log.vlog("No config file found, using defaults"); } diff --git a/src/main.d b/src/main.d index 995700a1..1c247e46 100644 --- a/src/main.d +++ b/src/main.d @@ -1,6 +1,6 @@ import core.stdc.stdlib: EXIT_SUCCESS, EXIT_FAILURE; import core.memory, core.time, core.thread; -import std.getopt, std.file, std.path, std.process, std.stdio; +import std.getopt, std.file, std.path, std.process, std.stdio, std.conv; import config, itemdb, monitor, onedrive, selective, sync, util; static import log; @@ -266,7 +266,8 @@ int main(string[] args) } if (monitor) { - log.vlog("Initializing monitor ..."); + log.log("Initializing monitor ..."); + log.log("OneDrive monitor interval (seconds): ", to!long(cfg.getValue("monitor_interval"))); Monitor m = new Monitor(selectiveSync); m.onDirCreated = delegate(string path) { log.vlog("[M] Directory created: ", path); @@ -302,13 +303,12 @@ int main(string[] args) }; if (!downloadOnly) m.init(cfg, verbose); // monitor loop - immutable auto checkInterval = dur!"seconds"(45); + immutable auto checkInterval = dur!"seconds"(to!long(cfg.getValue("monitor_interval"))); auto lastCheckTime = MonoTime.currTime(); while (true) { if (!downloadOnly) m.update(online); auto currTime = MonoTime.currTime(); if (currTime - lastCheckTime > checkInterval) { - lastCheckTime = currTime; online = testNetwork(); if (online) { performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly); @@ -317,19 +317,19 @@ int main(string[] args) m.update(false); } } + // performSync complete, set lastCheckTime to current time + lastCheckTime = MonoTime.currTime(); GC.collect(); } else { Thread.sleep(dur!"msecs"(100)); } } } - } // workaround for segfault in std.net.curl.Curl.shutdown() on exit onedrive.http.shutdown(); return EXIT_SUCCESS; - } // try to synchronize the folder three times