mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-10 09:46:40 +02:00
* Implement Feature: Make checkinterval for monitor configurable * Update monitor mode processing logic
This commit is contained in:
parent
b2270ee696
commit
e922a7d85e
|
@ -228,8 +228,9 @@ This file does not get created by default, and should only be created if you wan
|
||||||
|
|
||||||
Available options:
|
Available options:
|
||||||
* `sync_dir`: directory where the files will be synced
|
* `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
|
* `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
|
### sync_dir
|
||||||
Example: `sync_dir="~/MyDirToSync"`
|
Example: `sync_dir="~/MyDirToSync"`
|
||||||
|
@ -251,6 +252,11 @@ Example: `skip_symlinks = "true"`
|
||||||
|
|
||||||
Setting this to `"true"` will skip all symlinks while syncing.
|
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
|
||||||
Selective sync allows you to sync only specific files and directories.
|
Selective sync allows you to sync only specific files and directories.
|
||||||
To enable selective sync create a file named `sync_list` in `~/.config/onedrive`.
|
To enable selective sync create a file named `sync_list` in `~/.config/onedrive`.
|
||||||
|
|
2
config
2
config
|
@ -2,3 +2,5 @@
|
||||||
sync_dir = "~/OneDrive"
|
sync_dir = "~/OneDrive"
|
||||||
# Skip files and directories that match this pattern
|
# Skip files and directories that match this pattern
|
||||||
skip_file = ".*|~*"
|
skip_file = ".*|~*"
|
||||||
|
# Wait time (seconds) between sync operations in monitor mode
|
||||||
|
monitor_interval = "45"
|
||||||
|
|
|
@ -33,8 +33,12 @@ final class Config
|
||||||
// By default symlinks are not skipped (using string type
|
// By default symlinks are not skipped (using string type
|
||||||
// instead of boolean because hashmap only stores string types)
|
// instead of boolean because hashmap only stores string types)
|
||||||
setValue("skip_symlinks", "false");
|
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
|
// By default we will process remote deletes
|
||||||
setValue("no-remote-delete", "false");
|
setValue("no-remote-delete", "false");
|
||||||
|
|
||||||
if (!load(userConfigFilePath)) {
|
if (!load(userConfigFilePath)) {
|
||||||
log.vlog("No config file found, using defaults");
|
log.vlog("No config file found, using defaults");
|
||||||
}
|
}
|
||||||
|
|
12
src/main.d
12
src/main.d
|
@ -1,6 +1,6 @@
|
||||||
import core.stdc.stdlib: EXIT_SUCCESS, EXIT_FAILURE;
|
import core.stdc.stdlib: EXIT_SUCCESS, EXIT_FAILURE;
|
||||||
import core.memory, core.time, core.thread;
|
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;
|
import config, itemdb, monitor, onedrive, selective, sync, util;
|
||||||
static import log;
|
static import log;
|
||||||
|
|
||||||
|
@ -266,7 +266,8 @@ int main(string[] args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor) {
|
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);
|
Monitor m = new Monitor(selectiveSync);
|
||||||
m.onDirCreated = delegate(string path) {
|
m.onDirCreated = delegate(string path) {
|
||||||
log.vlog("[M] Directory created: ", path);
|
log.vlog("[M] Directory created: ", path);
|
||||||
|
@ -302,13 +303,12 @@ int main(string[] args)
|
||||||
};
|
};
|
||||||
if (!downloadOnly) m.init(cfg, verbose);
|
if (!downloadOnly) m.init(cfg, verbose);
|
||||||
// monitor loop
|
// monitor loop
|
||||||
immutable auto checkInterval = dur!"seconds"(45);
|
immutable auto checkInterval = dur!"seconds"(to!long(cfg.getValue("monitor_interval")));
|
||||||
auto lastCheckTime = MonoTime.currTime();
|
auto lastCheckTime = MonoTime.currTime();
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!downloadOnly) m.update(online);
|
if (!downloadOnly) m.update(online);
|
||||||
auto currTime = MonoTime.currTime();
|
auto currTime = MonoTime.currTime();
|
||||||
if (currTime - lastCheckTime > checkInterval) {
|
if (currTime - lastCheckTime > checkInterval) {
|
||||||
lastCheckTime = currTime;
|
|
||||||
online = testNetwork();
|
online = testNetwork();
|
||||||
if (online) {
|
if (online) {
|
||||||
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly);
|
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly);
|
||||||
|
@ -317,19 +317,19 @@ int main(string[] args)
|
||||||
m.update(false);
|
m.update(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// performSync complete, set lastCheckTime to current time
|
||||||
|
lastCheckTime = MonoTime.currTime();
|
||||||
GC.collect();
|
GC.collect();
|
||||||
} else {
|
} else {
|
||||||
Thread.sleep(dur!"msecs"(100));
|
Thread.sleep(dur!"msecs"(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// workaround for segfault in std.net.curl.Curl.shutdown() on exit
|
// workaround for segfault in std.net.curl.Curl.shutdown() on exit
|
||||||
onedrive.http.shutdown();
|
onedrive.http.shutdown();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to synchronize the folder three times
|
// try to synchronize the folder three times
|
||||||
|
|
Loading…
Reference in a new issue