From 764975e2247eae9a7b4b6ea13de21584bfa3beb1 Mon Sep 17 00:00:00 2001 From: skilion Date: Sun, 31 Dec 2017 17:07:21 +0100 Subject: [PATCH] download only option --- src/main.d | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main.d b/src/main.d index dace3db5..bfb771bd 100644 --- a/src/main.d +++ b/src/main.d @@ -4,6 +4,9 @@ import std.getopt, std.file, std.path, std.process, std.stdio; import config, itemdb, monitor, onedrive, selective, sync, util; static import log; +// only download remote changes +bool downloadOnly; + int main(string[] args) { // configuration directory @@ -29,6 +32,7 @@ int main(string[] args) std.getopt.config.bundling, std.getopt.config.caseSensitive, "confdir", "Set the directory used to store the configuration files", &configDirName, + "download|d", "Only download remote changes", &downloadOnly, "logout", "Logout the current user", &logout, "monitor|m", "Keep monitoring for local and remote changes", &monitor, "print-token", "Print the access token, useful for debugging", &printAccessToken, @@ -148,20 +152,22 @@ int main(string[] args) log.log(e.msg); } }; - m.init(cfg, verbose); + if (!downloadOnly) m.init(cfg, verbose); // monitor loop immutable auto checkInterval = dur!"seconds"(45); auto lastCheckTime = MonoTime.currTime(); while (true) { - m.update(online); + if (!downloadOnly) m.update(online); auto currTime = MonoTime.currTime(); if (currTime - lastCheckTime > checkInterval) { lastCheckTime = currTime; online = testNetwork(); if (online) { performSync(sync); - // discard all events that may have been generated by the sync - m.update(false); + if (!downloadOnly) { + // discard all events that may have been generated by the sync + m.update(false); + } } GC.collect(); } else { @@ -182,9 +188,14 @@ void performSync(SyncEngine sync) do { try { sync.applyDifferences(); - sync.scanForDifferences("."); + if (!downloadOnly) { + sync.scanForDifferences(); + // HACK: file metadata are often changed by OneDrive after an upload + sync.applyDifferences(); + } count = -1; } catch (Exception e) { + throw e; if (++count == 3) throw e; else log.log(e.msg); }