mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-02 22:13:16 +02:00
Handle HTTP request returned status code 412 (Precondition Failed) for session uploads (#227)
* Handle HTTP request returned status code 412 (Precondition Failed) for session uploads to OneDrive Personal Accounts * Fix Failed to remove file /root/.config/onedrive/resume_upload: No such file or directory if there is a session upload error and the resume file does not get created * Handle response codes when using 2 different systems using --upload-only but the same OneDrive account and uploading the same filename to the same location
This commit is contained in:
parent
11e477f045
commit
86ea576144
28
src/sync.d
28
src/sync.d
|
@ -977,6 +977,14 @@ final class SyncEngine
|
|||
try {
|
||||
response = onedrive.simpleUploadReplace(path, item.driveId, item.id, item.eTag);
|
||||
} catch (OneDriveException e) {
|
||||
if (e.httpStatusCode == 404) {
|
||||
// HTTP request returned status code 404 - the eTag provided does not exist
|
||||
// Delete record from the local database - file will be uploaded as a new file
|
||||
log.vlog("OneDrive returned a 'HTTP 404 - eTag Issue' - gracefully handling error");
|
||||
itemdb.deleteById(item.driveId, item.id);
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve https://github.com/abraunegg/onedrive/issues/36
|
||||
if ((e.httpStatusCode == 409) || (e.httpStatusCode == 423)) {
|
||||
// The file is currently checked out or locked for editing by another user
|
||||
|
@ -990,10 +998,10 @@ final class SyncEngine
|
|||
|
||||
if (e.httpStatusCode == 412) {
|
||||
// HTTP request returned status code 412 - ETag does not match current item's value
|
||||
// Remove the offending file from OneDrive - file will be uploaded as a new file
|
||||
onedrive.deleteById(item.driveId, item.id, item.eTag);
|
||||
// Delete from the local database
|
||||
// Delete record from the local database - file will be uploaded as a new file
|
||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
||||
itemdb.deleteById(item.driveId, item.id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.httpStatusCode == 504) {
|
||||
|
@ -1006,7 +1014,17 @@ final class SyncEngine
|
|||
writeln("done.");
|
||||
} else {
|
||||
writeln("");
|
||||
response = session.upload(path, item.driveId, item.parentId, baseName(path), item.eTag);
|
||||
try {
|
||||
response = session.upload(path, item.driveId, item.parentId, baseName(path), item.eTag);
|
||||
} catch (OneDriveException e) {
|
||||
if (e.httpStatusCode == 412) {
|
||||
// HTTP request returned status code 412 - ETag does not match current item's value
|
||||
// Delete record from the local database - file will be uploaded as a new file
|
||||
log.vlog("OneDrive returned a 'HTTP 412 - Precondition Failed' - gracefully handling error");
|
||||
itemdb.deleteById(item.driveId, item.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
writeln("done.");
|
||||
}
|
||||
} else {
|
||||
|
@ -1034,7 +1052,7 @@ final class SyncEngine
|
|||
saveItem(response);
|
||||
}
|
||||
log.fileOnly("Uploading file ", path, " ... done.");
|
||||
// use the cTag instead of the eTag because OneDrive may update the metadata of files AFTER they have been uploaded
|
||||
// use the cTag instead of the eTag because OneDrive may update the metadata of files AFTER they have been uploaded via simple upload
|
||||
eTag = response["cTag"].str;
|
||||
}
|
||||
if (accountType == "personal"){
|
||||
|
|
16
src/upload.d
16
src/upload.d
|
@ -92,13 +92,17 @@ struct UploadSession
|
|||
} else {
|
||||
// unable to read the local file
|
||||
log.vlog("Restore file upload session failed - unable to read the local file");
|
||||
remove(sessionFilePath);
|
||||
if (exists(sessionFilePath)) {
|
||||
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);
|
||||
if (exists(sessionFilePath)) {
|
||||
remove(sessionFilePath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -136,14 +140,18 @@ struct UploadSession
|
|||
save();
|
||||
} catch (OneDriveException e) {
|
||||
// there was an error remove session file
|
||||
remove(sessionFilePath);
|
||||
if (exists(sessionFilePath)) {
|
||||
remove(sessionFilePath);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
// upload complete
|
||||
p.next();
|
||||
writeln();
|
||||
remove(sessionFilePath);
|
||||
if (exists(sessionFilePath)) {
|
||||
remove(sessionFilePath);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue