Revert "Fix unhandled monitor initialisation exception"

This reverts commit e1be2b1e55.
This commit is contained in:
abraunegg 2019-10-30 06:33:11 +11:00
parent e1be2b1e55
commit 9b3179540f

View file

@ -671,82 +671,72 @@ int main(string[] args)
signal(SIGINT, &exitHandler); signal(SIGINT, &exitHandler);
signal(SIGTERM, &exitHandler); signal(SIGTERM, &exitHandler);
// attempt to initialise monitor class // initialise the monitor class
try { if (!cfg.getValueBool("download_only")) m.init(cfg, cfg.getValueLong("verbose") > 0, cfg.getValueBool("skip_symlinks"), cfg.getValueBool("check_nosync"));
m.init(cfg, cfg.getValueLong("verbose") > 0, cfg.getValueBool("skip_symlinks"), cfg.getValueBool("check_nosync")); // monitor loop
} catch (MonitorException e) { immutable auto checkInterval = dur!"seconds"(cfg.getValueLong("monitor_interval"));
// monitor initialisation failed immutable auto logInterval = cfg.getValueLong("monitor_log_frequency");
log.error("ERROR: ", e.msg); immutable auto fullScanFrequency = cfg.getValueLong("monitor_fullscan_frequency");
exit(-1); auto lastCheckTime = MonoTime.currTime();
} auto logMonitorCounter = 0;
auto fullScanCounter = 0;
//if (!cfg.getValueBool("download_only")) m.init(cfg, cfg.getValueLong("verbose") > 0, cfg.getValueBool("skip_symlinks"), cfg.getValueBool("check_nosync")); bool fullScanRequired = true;
if (!cfg.getValueBool("download_only")) { bool syncListConfiguredOverride = false;
// monitor loop while (true) {
immutable auto checkInterval = dur!"seconds"(cfg.getValueLong("monitor_interval")); if (!cfg.getValueBool("download_only")) m.update(online);
immutable auto logInterval = cfg.getValueLong("monitor_log_frequency"); auto currTime = MonoTime.currTime();
immutable auto fullScanFrequency = cfg.getValueLong("monitor_fullscan_frequency"); if (currTime - lastCheckTime > checkInterval) {
auto lastCheckTime = MonoTime.currTime(); // log monitor output suppression
auto logMonitorCounter = 0; logMonitorCounter += 1;
auto fullScanCounter = 0; if (logMonitorCounter > logInterval)
bool fullScanRequired = true; logMonitorCounter = 1;
bool syncListConfiguredOverride = false;
while (true) { // full scan of sync_dir
if (!cfg.getValueBool("download_only")) m.update(online); fullScanCounter += 1;
auto currTime = MonoTime.currTime(); if (fullScanCounter > fullScanFrequency){
if (currTime - lastCheckTime > checkInterval) { fullScanCounter = 1;
// log monitor output suppression fullScanRequired = true;
logMonitorCounter += 1; if (syncListConfigured) {
if (logMonitorCounter > logInterval) syncListConfiguredOverride = true;
logMonitorCounter = 1; }
}
// full scan of sync_dir
fullScanCounter += 1; // log.logAndNotify("DEBUG trying to create checkpoint");
if (fullScanCounter > fullScanFrequency){ // auto res = itemdb.db_checkpoint();
fullScanCounter = 1; // log.logAndNotify("Checkpoint return: ", res);
fullScanRequired = true; // itemdb.dump_open_statements();
if (syncListConfigured) {
syncListConfiguredOverride = true; try {
} if (!initSyncEngine(sync)) {
oneDrive.http.shutdown();
return EXIT_FAILURE;
} }
// log.logAndNotify("DEBUG trying to create checkpoint");
// auto res = itemdb.db_checkpoint();
// log.logAndNotify("Checkpoint return: ", res);
// itemdb.dump_open_statements();
try { try {
if (!initSyncEngine(sync)) { // perform a --monitor sync
oneDrive.http.shutdown(); 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), fullScanRequired, syncListConfiguredOverride);
return EXIT_FAILURE; if (!cfg.getValueBool("download_only")) {
} // discard all events that may have been generated by the sync
try { m.update(false);
// perform a --monitor sync
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), fullScanRequired, syncListConfiguredOverride);
if (!cfg.getValueBool("download_only")) {
// discard all events that may have been generated by the sync
m.update(false);
}
} catch (CurlException e) {
// we already tried three times in the performSync routine
// if we still have problems, then the sync handle might have
// gone stale and we need to re-initialize the sync engine
log.log("Persistent connection errors, reinitializing connection");
sync.reset();
} }
} catch (CurlException e) { } catch (CurlException e) {
log.log("Cannot initialize connection to OneDrive"); // we already tried three times in the performSync routine
// if we still have problems, then the sync handle might have
// gone stale and we need to re-initialize the sync engine
log.log("Persistent connection errors, reinitializing connection");
sync.reset();
} }
// performSync complete, set lastCheckTime to current time } catch (CurlException e) {
fullScanRequired = false; log.log("Cannot initialize connection to OneDrive");
if (syncListConfigured) { }
syncListConfiguredOverride = false; // performSync complete, set lastCheckTime to current time
} fullScanRequired = false;
lastCheckTime = MonoTime.currTime(); if (syncListConfigured) {
GC.collect(); syncListConfiguredOverride = false;
} }
Thread.sleep(dur!"msecs"(500)); lastCheckTime = MonoTime.currTime();
} GC.collect();
}
Thread.sleep(dur!"msecs"(500));
} }
} }
} }