mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-03 14:32:24 +02:00
Merge branch 'master' into norbert/config-options
This commit is contained in:
commit
388a3bb102
|
@ -45,6 +45,8 @@ final class Config
|
||||||
longValues["verbose"] = 0;
|
longValues["verbose"] = 0;
|
||||||
longValues["monitor_interval"] = 45,
|
longValues["monitor_interval"] = 45,
|
||||||
longValues["min_notif_changes"] = 5;
|
longValues["min_notif_changes"] = 5;
|
||||||
|
longValues["min_notif_changes"] = 5;
|
||||||
|
longValues["monitor_log_frequency"] = 5;
|
||||||
|
|
||||||
// Determine the users home directory.
|
// 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
|
// 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",
|
"monitor|m",
|
||||||
"Keep monitoring for local and remote changes",
|
"Keep monitoring for local and remote changes",
|
||||||
&boolValues["monitor"],
|
&boolValues["monitor"],
|
||||||
|
"monitor-log-frequency",
|
||||||
|
"Frequency of logging in monitor mode",
|
||||||
|
&longValues["monitor_log_frequency"],
|
||||||
"no-remote-delete",
|
"no-remote-delete",
|
||||||
"Do not delete local file 'deletes' from OneDrive when using --upload-only",
|
"Do not delete local file 'deletes' from OneDrive when using --upload-only",
|
||||||
&boolValues["no_remote_delete"],
|
&boolValues["no_remote_delete"],
|
||||||
|
|
29
src/main.d
29
src/main.d
|
@ -10,6 +10,10 @@ static import log;
|
||||||
OneDriveApi oneDrive;
|
OneDriveApi oneDrive;
|
||||||
ItemDatabase itemDb;
|
ItemDatabase itemDb;
|
||||||
|
|
||||||
|
enum MONITOR_LOG_SILENT = 2;
|
||||||
|
enum MONITOR_LOG_QUIET = 1;
|
||||||
|
enum LOG_NORMAL = 0;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
// Disable buffering on stdout
|
// Disable buffering on stdout
|
||||||
|
@ -328,7 +332,7 @@ int main(string[] args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the sync
|
// 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"));
|
if (!cfg.getValueBool("download_only")) m.init(cfg, cfg.getValueLong("verbose") > 0, cfg.getValueBool("skip_symlinks"));
|
||||||
// monitor loop
|
// monitor loop
|
||||||
immutable auto checkInterval = dur!"seconds"(cfg.getValueLong("monitor_interval"));
|
immutable auto checkInterval = dur!"seconds"(cfg.getValueLong("monitor_interval"));
|
||||||
|
immutable auto logInterval = cfg.getValueLong("monitor_log_frequency");
|
||||||
auto lastCheckTime = MonoTime.currTime();
|
auto lastCheckTime = MonoTime.currTime();
|
||||||
|
auto logMonitorCounter = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!cfg.getValueBool("download_only")) m.update(online);
|
if (!cfg.getValueBool("download_only")) m.update(online);
|
||||||
auto currTime = MonoTime.currTime();
|
auto currTime = MonoTime.currTime();
|
||||||
if (currTime - lastCheckTime > checkInterval) {
|
if (currTime - lastCheckTime > checkInterval) {
|
||||||
|
logMonitorCounter += 1;
|
||||||
|
if (logMonitorCounter > logInterval)
|
||||||
|
logMonitorCounter = 1;
|
||||||
// log.logAndNotify("DEBUG trying to create checkpoint");
|
// log.logAndNotify("DEBUG trying to create checkpoint");
|
||||||
// auto res = itemdb.db_checkpoint();
|
// auto res = itemdb.db_checkpoint();
|
||||||
// log.logAndNotify("Checkpoint return: ", res);
|
// log.logAndNotify("Checkpoint return: ", res);
|
||||||
|
@ -404,7 +413,7 @@ int main(string[] args)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
try {
|
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")) {
|
if (!cfg.getValueBool("download_only")) {
|
||||||
// discard all events that may have been generated by the sync
|
// discard all events that may have been generated by the sync
|
||||||
m.update(false);
|
m.update(false);
|
||||||
|
@ -413,7 +422,7 @@ int main(string[] args)
|
||||||
// we already tried three times in the performSync routine
|
// we already tried three times in the performSync routine
|
||||||
// if we still have problems, then the sync handle might have
|
// if we still have problems, then the sync handle might have
|
||||||
// gone stale and we need to re-initialize the sync engine
|
// 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();
|
sync.reset();
|
||||||
}
|
}
|
||||||
} catch (CurlException e) {
|
} catch (CurlException e) {
|
||||||
|
@ -452,7 +461,7 @@ bool initSyncEngine(SyncEngine sync)
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to synchronize the folder three times
|
// 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;
|
int count;
|
||||||
string remotePath = "/";
|
string remotePath = "/";
|
||||||
|
@ -472,18 +481,18 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
|
||||||
log.vlog("Syncing changes from this selected path: ", singleDirectory);
|
log.vlog("Syncing changes from this selected path: ", singleDirectory);
|
||||||
if (uploadOnly){
|
if (uploadOnly){
|
||||||
// Upload Only of selected single directory
|
// 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);
|
sync.scanForDifferences(localPath);
|
||||||
} else {
|
} else {
|
||||||
// No upload only
|
// No upload only
|
||||||
if (localFirst) {
|
if (localFirst) {
|
||||||
// Local First
|
// 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.scanForDifferences(localPath);
|
||||||
sync.applyDifferencesSingleDirectory(remotePath);
|
sync.applyDifferencesSingleDirectory(remotePath);
|
||||||
} else {
|
} else {
|
||||||
// OneDrive First
|
// 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);
|
sync.applyDifferencesSingleDirectory(remotePath);
|
||||||
// is this a download only request?
|
// is this a download only request?
|
||||||
if (!downloadOnly) {
|
if (!downloadOnly) {
|
||||||
|
@ -498,18 +507,18 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
|
||||||
// no single directory sync
|
// no single directory sync
|
||||||
if (uploadOnly){
|
if (uploadOnly){
|
||||||
// Upload Only of entire sync_dir
|
// 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);
|
sync.scanForDifferences(localPath);
|
||||||
} else {
|
} else {
|
||||||
// No upload only
|
// No upload only
|
||||||
if (localFirst) {
|
if (localFirst) {
|
||||||
// sync local files first before downloading from OneDrive
|
// 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.scanForDifferences(localPath);
|
||||||
sync.applyDifferences();
|
sync.applyDifferences();
|
||||||
} else {
|
} else {
|
||||||
// sync from OneDrive first before uploading files to OneDrive
|
// 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();
|
sync.applyDifferences();
|
||||||
// is this a download only request?
|
// is this a download only request?
|
||||||
if (!downloadOnly) {
|
if (!downloadOnly) {
|
||||||
|
|
|
@ -208,7 +208,7 @@ final class SyncEngine
|
||||||
this.onedrive = onedrive;
|
this.onedrive = onedrive;
|
||||||
this.itemdb = itemdb;
|
this.itemdb = itemdb;
|
||||||
this.selectiveSync = selectiveSync;
|
this.selectiveSync = selectiveSync;
|
||||||
session = UploadSession(onedrive, cfg.uploadStateFilePath);
|
// session = UploadSession(onedrive, cfg.uploadStateFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
|
@ -226,6 +226,8 @@ final class SyncEngine
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session = UploadSession(onedrive, cfg.uploadStateFilePath);
|
||||||
|
|
||||||
// Need to catch 400 or 5xx server side errors at initialization
|
// Need to catch 400 or 5xx server side errors at initialization
|
||||||
try {
|
try {
|
||||||
oneDriveDetails = onedrive.getDefaultDrive();
|
oneDriveDetails = onedrive.getDefaultDrive();
|
||||||
|
|
Loading…
Reference in a new issue