mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-21 07:06:40 +02:00
Fix crash when resume_upload file is not a valid JSON (#664)
* Validate that there is JSON data in the string before the string is read via parseJSON() * Add try block to catch file system exceptions if they are generated when attempting to update the file date & time
This commit is contained in:
parent
72467e32ca
commit
fd4547376c
14
src/sync.d
14
src/sync.d
|
@ -1342,7 +1342,12 @@ final class SyncEngine
|
|||
|
||||
// handle changed time
|
||||
if (newItem.type == ItemType.file && oldItem.mtime != newItem.mtime) {
|
||||
setTimes(newPath, newItem.mtime, newItem.mtime);
|
||||
try {
|
||||
setTimes(newPath, newItem.mtime, newItem.mtime);
|
||||
} catch (FileException e) {
|
||||
// display the error message
|
||||
displayFileSystemErrorMessage(e.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1457,7 +1462,12 @@ final class SyncEngine
|
|||
if ((getSize(path) == fileSize) || (OneDriveFileHash == quickXorHash) || (OneDriveFileHash == sha1Hash)) {
|
||||
// downloaded matches either size or hash
|
||||
log.vdebug("Downloaded file matches reported size and or reported file hash");
|
||||
setTimes(path, item.mtime, item.mtime);
|
||||
try {
|
||||
setTimes(path, item.mtime, item.mtime);
|
||||
} catch (FileException e) {
|
||||
// display the error message
|
||||
displayFileSystemErrorMessage(e.msg);
|
||||
}
|
||||
} else {
|
||||
// size error?
|
||||
if (getSize(path) != fileSize) {
|
||||
|
|
11
src/upload.d
11
src/upload.d
|
@ -62,7 +62,16 @@ struct UploadSession
|
|||
{
|
||||
if (exists(sessionFilePath)) {
|
||||
log.vlog("Trying to restore the upload session ...");
|
||||
session = readText(sessionFilePath).parseJSON();
|
||||
// We cant use JSONType.object check, as this is currently a string
|
||||
// We cant use a try & catch block, as it does not catch std.json.JSONException
|
||||
auto sessionFileText = readText(sessionFilePath);
|
||||
if(canFind(sessionFileText,"@odata.context")) {
|
||||
session = readText(sessionFilePath).parseJSON();
|
||||
} else {
|
||||
log.vlog("Upload session resume data is invalid");
|
||||
remove(sessionFilePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the session resume file for expirationDateTime
|
||||
if ("expirationDateTime" in session){
|
||||
|
|
Loading…
Reference in a new issue