From 4667ecad12b760f643e0f9287986a5ab15028a6b Mon Sep 17 00:00:00 2001 From: abraunegg Date: Tue, 10 Jul 2018 10:30:22 +1000 Subject: [PATCH] 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) --- src/sync.d | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/sync.d b/src/sync.d index cf83e76b..629663a1 100644 --- a/src/sync.d +++ b/src/sync.d @@ -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);