mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-11 02:06:40 +02:00
Reinitialize sync engine after three failed trials (#283)
* After extended suspend, or bad connection, the connection to OD might go stale - thus no network connection to Microsoft OneDrive Service, skipping sync and this continues ad infinitum. Change the last action to re-initialize the sync engine.
This commit is contained in:
parent
6a62406db7
commit
91aaf91aa6
29
src/main.d
29
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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue