Fix unhandled monitor initialisation exception

* Catch MonitorException when initialisation failure occurs, print error and exit ... cant enter monitor loop if we cant initialise correctly.
This commit is contained in:
abraunegg 2019-10-30 06:32:17 +11:00
parent fec892b038
commit e1be2b1e55

View file

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