mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-21 07:06:40 +02:00
Update sync.d (#422)
* Add a check to validate if 'size' is in the JSON response
This commit is contained in:
parent
58c2805237
commit
6b8b51a7cc
79
src/sync.d
79
src/sync.d
|
@ -1771,47 +1771,50 @@ final class SyncEngine
|
|||
// Log action to log file
|
||||
log.fileOnly("Uploading new file ", path, " ... done.");
|
||||
|
||||
// The file was uploaded
|
||||
ulong uploadFileSize = response["size"].integer;
|
||||
|
||||
// In some cases the file that was uploaded was not complete, but 'completed' without errors on OneDrive
|
||||
// This has been seen with PNG / JPG files mainly, which then contributes to generating a 412 error when we attempt to update the metadata
|
||||
// Validate here that the file uploaded, at least in size, matches in the response to what the size is on disk
|
||||
if (thisFileSize != uploadFileSize){
|
||||
if(disableUploadValidation){
|
||||
// Print a warning message
|
||||
log.log("WARNING: Uploaded file size does not match local file - skipping upload validation");
|
||||
// The file was uploaded, or a 4xx / 5xx error was generated
|
||||
if ("size" in response){
|
||||
// The response JSON contains size, high likelihood valid response returned
|
||||
ulong uploadFileSize = response["size"].integer;
|
||||
|
||||
// In some cases the file that was uploaded was not complete, but 'completed' without errors on OneDrive
|
||||
// This has been seen with PNG / JPG files mainly, which then contributes to generating a 412 error when we attempt to update the metadata
|
||||
// Validate here that the file uploaded, at least in size, matches in the response to what the size is on disk
|
||||
if (thisFileSize != uploadFileSize){
|
||||
if(disableUploadValidation){
|
||||
// Print a warning message
|
||||
log.log("WARNING: Uploaded file size does not match local file - skipping upload validation");
|
||||
} else {
|
||||
// OK .. the uploaded file does not match and we did not disable this validation
|
||||
log.log("Uploaded file size does not match local file - upload failure - retrying");
|
||||
// Delete uploaded bad file
|
||||
onedrive.deleteById(response["parentReference"]["driveId"].str, response["id"].str, response["eTag"].str);
|
||||
// Re-upload
|
||||
uploadNewFile(path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// File validation is OK
|
||||
if ((accountType == "personal") || (thisFileSize == 0)){
|
||||
// Update the item's metadata on OneDrive
|
||||
string id = response["id"].str;
|
||||
string cTag = response["cTag"].str;
|
||||
if (exists(path)) {
|
||||
SysTime mtime = timeLastModified(path).toUTC();
|
||||
// use the cTag instead of the eTag because OneDrive may update the metadata of files AFTER they have been uploaded
|
||||
uploadLastModifiedTime(parent.driveId, id, cTag, mtime);
|
||||
} else {
|
||||
// will be removed in different event!
|
||||
log.log("File disappeared after upload: ", path);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// OK .. the uploaded file does not match and we did not disable this validation
|
||||
log.log("Uploaded file size does not match local file - upload failure - retrying");
|
||||
// Delete uploaded bad file
|
||||
onedrive.deleteById(response["parentReference"]["driveId"].str, response["id"].str, response["eTag"].str);
|
||||
// Re-upload
|
||||
uploadNewFile(path);
|
||||
// OneDrive Business Account - always use a session to upload
|
||||
// The session includes a Request Body element containing lastModifiedDateTime
|
||||
// which negates the need for a modify event against OneDrive
|
||||
saveItem(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// File validation is OK
|
||||
if ((accountType == "personal") || (thisFileSize == 0)){
|
||||
// Update the item's metadata on OneDrive
|
||||
string id = response["id"].str;
|
||||
string cTag = response["cTag"].str;
|
||||
if (exists(path)) {
|
||||
SysTime mtime = timeLastModified(path).toUTC();
|
||||
// use the cTag instead of the eTag because OneDrive may update the metadata of files AFTER they have been uploaded
|
||||
uploadLastModifiedTime(parent.driveId, id, cTag, mtime);
|
||||
} else {
|
||||
// will be removed in different event!
|
||||
log.log("File disappeared after upload: ", path);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// OneDrive Business Account - always use a session to upload
|
||||
// The session includes a Request Body element containing lastModifiedDateTime
|
||||
// which negates the need for a modify event against OneDrive
|
||||
saveItem(response);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// we are --dry-run - simulate the file upload
|
||||
|
|
Loading…
Reference in a new issue