mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-17 05:06:17 +02:00
* Handle an invalid response on session resume when a 4xx / 5xx response is generated from the OneDrive service
This commit is contained in:
parent
14b2de8f4c
commit
74b9163b06
20
src/upload.d
20
src/upload.d
|
@ -53,6 +53,10 @@ struct UploadSession
|
|||
if (exists(sessionFilePath)) {
|
||||
log.vlog("Trying to restore the upload session ...");
|
||||
session = readText(sessionFilePath).parseJSON();
|
||||
|
||||
// Check the session resume file for expirationDateTime
|
||||
if ("expirationDateTime" in session){
|
||||
// expirationDateTime in the file
|
||||
auto expiration = SysTime.fromISOExtString(session["expirationDateTime"].str);
|
||||
if (expiration < Clock.currTime()) {
|
||||
log.vlog("The upload session is expired");
|
||||
|
@ -87,6 +91,13 @@ struct UploadSession
|
|||
return true;
|
||||
} else {
|
||||
// unable to read the local file
|
||||
log.vlog("Restore file upload session failed - unable to read the local file");
|
||||
remove(sessionFilePath);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// session file contains an error - cant resume
|
||||
log.vlog("Restore file upload session failed - cleaning up session resume");
|
||||
remove(sessionFilePath);
|
||||
return false;
|
||||
}
|
||||
|
@ -108,6 +119,8 @@ struct UploadSession
|
|||
while (true) {
|
||||
p.next();
|
||||
long fragSize = fragmentSize < fileSize - offset ? fragmentSize : fileSize - offset;
|
||||
// If the resume upload fails, we need to check for a return code here
|
||||
try {
|
||||
response = onedrive.uploadFragment(
|
||||
session["uploadUrl"].str,
|
||||
session["localPath"].str,
|
||||
|
@ -117,10 +130,15 @@ struct UploadSession
|
|||
);
|
||||
offset += fragmentSize;
|
||||
if (offset >= fileSize) break;
|
||||
// update the session
|
||||
// update the session details
|
||||
session["expirationDateTime"] = response["expirationDateTime"];
|
||||
session["nextExpectedRanges"] = response["nextExpectedRanges"];
|
||||
save();
|
||||
} catch (OneDriveException e) {
|
||||
// there was an error remove session file
|
||||
remove(sessionFilePath);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
// upload complete
|
||||
p.next();
|
||||
|
|
Loading…
Reference in a new issue