mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-21 23:26:37 +02:00
* Configurable interval of logging in monitor mode (Issue: #378)
This commit is contained in:
parent
b668ecef71
commit
09f328e63f
|
@ -45,6 +45,8 @@ final class Config
|
|||
setValue("drive_id", "");
|
||||
// Minimal changes that trigger a log and notification on sync
|
||||
setValue("min_notif_changes", "5");
|
||||
// Frequency of log messages in monitor, ie after n sync runs ship out a log message
|
||||
setValue("monitor_log_frequency", "5");
|
||||
|
||||
if (!load(userConfigFilePath)) {
|
||||
// What was the reason for failure?
|
||||
|
|
27
src/main.d
27
src/main.d
|
@ -10,6 +10,10 @@ static import log;
|
|||
OneDriveApi oneDrive;
|
||||
ItemDatabase itemDb;
|
||||
|
||||
enum MONITOR_LOG_SILENT = 2;
|
||||
enum MONITOR_LOG_QUIET = 1;
|
||||
enum LOG_NORMAL = 0;
|
||||
|
||||
int main(string[] args)
|
||||
{
|
||||
// Disable buffering on stdout
|
||||
|
@ -491,7 +495,7 @@ int main(string[] args)
|
|||
}
|
||||
|
||||
// Perform the sync
|
||||
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, monitor);
|
||||
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, LOG_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -553,11 +557,16 @@ int main(string[] args)
|
|||
if (!downloadOnly) m.init(cfg, verbose, skipSymlinks);
|
||||
// monitor loop
|
||||
immutable auto checkInterval = dur!"seconds"(to!long(cfg.getValue("monitor_interval")));
|
||||
immutable auto logInterval = to!long(cfg.getValue("monitor_log_frequency"));
|
||||
auto lastCheckTime = MonoTime.currTime();
|
||||
auto logMonitorCounter = 0;
|
||||
while (true) {
|
||||
if (!downloadOnly) m.update(online);
|
||||
auto currTime = MonoTime.currTime();
|
||||
if (currTime - lastCheckTime > checkInterval) {
|
||||
logMonitorCounter += 1;
|
||||
if (logMonitorCounter > logInterval)
|
||||
logMonitorCounter = 1;
|
||||
// log.logAndNotify("DEBUG trying to create checkpoint");
|
||||
// auto res = itemdb.db_checkpoint();
|
||||
// log.logAndNotify("Checkpoint return: ", res);
|
||||
|
@ -568,7 +577,7 @@ int main(string[] args)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
try {
|
||||
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, monitor);
|
||||
performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly, (logMonitorCounter == logInterval ? MONITOR_LOG_QUIET : MONITOR_LOG_SILENT));
|
||||
if (!downloadOnly) {
|
||||
// discard all events that may have been generated by the sync
|
||||
m.update(false);
|
||||
|
@ -616,7 +625,7 @@ bool initSyncEngine(SyncEngine sync)
|
|||
}
|
||||
|
||||
// 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;
|
||||
string remotePath = "/";
|
||||
|
@ -636,18 +645,18 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
|
|||
log.vlog("Syncing changes from this selected path: ", singleDirectory);
|
||||
if (uploadOnly){
|
||||
// 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);
|
||||
} else {
|
||||
// No upload only
|
||||
if (localFirst) {
|
||||
// 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.applyDifferencesSingleDirectory(remotePath);
|
||||
} else {
|
||||
// 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);
|
||||
// is this a download only request?
|
||||
if (!downloadOnly) {
|
||||
|
@ -662,18 +671,18 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
|
|||
// no single directory sync
|
||||
if (uploadOnly){
|
||||
// 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);
|
||||
} else {
|
||||
// No upload only
|
||||
if (localFirst) {
|
||||
// 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.applyDifferences();
|
||||
} else {
|
||||
// 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();
|
||||
// is this a download only request?
|
||||
if (!downloadOnly) {
|
||||
|
|
Loading…
Reference in a new issue