diff --git a/src/main.d b/src/main.d index 0779ded7..e3304128 100644 --- a/src/main.d +++ b/src/main.d @@ -398,17 +398,21 @@ int main(string[] args) onedrive.http.shutdown(); return EXIT_FAILURE; } - performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly); - if (!downloadOnly) { - // discard all events that may have been generated by the sync - m.update(false); + try { + performSync(sync, singleDirectory, downloadOnly, localFirst, uploadOnly); + if (!downloadOnly) { + // 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("Pesistent connection errors, reinitializing connection"); + sync.reset(); } } catch (CurlException e) { - // TODO better check of type of exception from Curl - // could be either timeout of operation of connection error - // No network connection to OneDrive Service - // Don't overload notifications - log.log("No network connection to Microsoft OneDrive Service, skipping sync"); + log.log("Cannot initialize connection to OneDrive"); } // performSync complete, set lastCheckTime to current time lastCheckTime = MonoTime.currTime(); @@ -514,8 +518,11 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo } count = -1; } catch (Exception e) { - if (++count == 3) throw e; - else log.log("Retrial sync count: ", count, ": ", e.msg); + if (++count == 3) { + log.log("Giving up on sync after three attempts: ", e.msg); + throw e; + } else + log.log("Retry sync count: ", count, ": ", e.msg); } } while (count != -1); } diff --git a/src/sync.d b/src/sync.d index 135ae633..56474590 100644 --- a/src/sync.d +++ b/src/sync.d @@ -180,6 +180,11 @@ final class SyncEngine session = UploadSession(onedrive, cfg.uploadStateFilePath); } + void reset() + { + initDone=false; + } + void init() { // Set accountType, defaultDriveId, defaultRootId & remainingFreeSpace once and reuse where possible