Fix: Crash if file is locked by online editing (status code 423) (Issue #36) (#50)

* Resolve application crash if file is locked by online editing (status code 423)
This commit is contained in:
abraunegg 2018-07-10 10:30:22 +10:00 committed by GitHub
parent 9e971410ee
commit 4667ecad12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -836,6 +836,17 @@ final class SyncEngine
try {
response = onedrive.simpleUploadReplace(path, item.driveId, item.id, item.eTag);
} catch (OneDriveException e) {
// 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
// We cant upload this file at this time
writeln(" skipped.");
log.fileOnly("Uploading file ", path, " ... skipped.");
write("", path, " is currently checked out or locked for editing by another user.");
log.fileOnly(path, " is currently checked out or locked for editing by another user.");
return;
}
if (e.httpStatusCode == 504) {
// HTTP request returned status code 504 (Gateway Timeout)
// Try upload as a session
@ -852,7 +863,23 @@ final class SyncEngine
} else {
// OneDrive Business Account - always use a session to upload
writeln("");
response = session.upload(path, item.driveId, item.parentId, baseName(path));
try {
response = session.upload(path, item.driveId, item.parentId, baseName(path));
} catch (OneDriveException e) {
// 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
// We cant upload this file at this time
writeln(" skipped.");
log.fileOnly("Uploading file ", path, " ... skipped.");
writeln("", path, " is currently checked out or locked for editing by another user.");
log.fileOnly(path, " is currently checked out or locked for editing by another user.");
return;
}
}
writeln(" done.");
// As the session.upload includes the last modified time, save the response
saveItem(response);