mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-10 01:42:32 +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)) {
|
if (exists(sessionFilePath)) {
|
||||||
log.vlog("Trying to restore the upload session ...");
|
log.vlog("Trying to restore the upload session ...");
|
||||||
session = readText(sessionFilePath).parseJSON();
|
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);
|
auto expiration = SysTime.fromISOExtString(session["expirationDateTime"].str);
|
||||||
if (expiration < Clock.currTime()) {
|
if (expiration < Clock.currTime()) {
|
||||||
log.vlog("The upload session is expired");
|
log.vlog("The upload session is expired");
|
||||||
|
@ -87,6 +91,13 @@ struct UploadSession
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// unable to read the local file
|
// 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);
|
remove(sessionFilePath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -108,6 +119,8 @@ struct UploadSession
|
||||||
while (true) {
|
while (true) {
|
||||||
p.next();
|
p.next();
|
||||||
long fragSize = fragmentSize < fileSize - offset ? fragmentSize : fileSize - offset;
|
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(
|
response = onedrive.uploadFragment(
|
||||||
session["uploadUrl"].str,
|
session["uploadUrl"].str,
|
||||||
session["localPath"].str,
|
session["localPath"].str,
|
||||||
|
@ -117,10 +130,15 @@ struct UploadSession
|
||||||
);
|
);
|
||||||
offset += fragmentSize;
|
offset += fragmentSize;
|
||||||
if (offset >= fileSize) break;
|
if (offset >= fileSize) break;
|
||||||
// update the session
|
// update the session details
|
||||||
session["expirationDateTime"] = response["expirationDateTime"];
|
session["expirationDateTime"] = response["expirationDateTime"];
|
||||||
session["nextExpectedRanges"] = response["nextExpectedRanges"];
|
session["nextExpectedRanges"] = response["nextExpectedRanges"];
|
||||||
save();
|
save();
|
||||||
|
} catch (OneDriveException e) {
|
||||||
|
// there was an error remove session file
|
||||||
|
remove(sessionFilePath);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// upload complete
|
// upload complete
|
||||||
p.next();
|
p.next();
|
||||||
|
|
Loading…
Reference in a new issue