download only option

This commit is contained in:
skilion 2017-12-31 17:07:21 +01:00
parent 80cfdf62cf
commit 764975e224

View file

@ -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);
}