From d28009bc0b4ec5d08dc2de4e5bd7c9bc935ee958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Kunz?= Date: Fri, 3 May 2024 15:43:21 +0200 Subject: [PATCH] KDESKTOP-804 - Handle 404 errors differently depending on. the operation --- .../jobs/network/abstractnetworkjob.cpp | 1 + .../jobs/network/abstractnetworkjob.h | 4 ++++ .../propagation/executor/executorworker.cpp | 14 +++++++++++--- .../propagation/executor/executorworker.h | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libsyncengine/jobs/network/abstractnetworkjob.cpp b/src/libsyncengine/jobs/network/abstractnetworkjob.cpp index 768df9922..87ce04eb5 100644 --- a/src/libsyncengine/jobs/network/abstractnetworkjob.cpp +++ b/src/libsyncengine/jobs/network/abstractnetworkjob.cpp @@ -498,6 +498,7 @@ bool AbstractNetworkJob::followRedirect(std::istream &inputStream) { bool receiveOk = receiveResponse(session, uri); if (!receiveOk && _resHttp.getStatus() == Poco::Net::HTTPResponse::HTTP_NOT_FOUND) { // Special cases where the file exist in DB but not in storage + _downloadImpossible = true; return true; } return receiveOk; diff --git a/src/libsyncengine/jobs/network/abstractnetworkjob.h b/src/libsyncengine/jobs/network/abstractnetworkjob.h index d6a7aabe7..aeb043628 100644 --- a/src/libsyncengine/jobs/network/abstractnetworkjob.h +++ b/src/libsyncengine/jobs/network/abstractnetworkjob.h @@ -44,6 +44,8 @@ class AbstractNetworkJob : public AbstractJob { inline Poco::Net::HTTPResponse::HTTPStatus getStatusCode() const { return _resHttp.getStatus(); } virtual void abort() override; + inline bool isDownloadImpossible() const { return _downloadImpossible; } + protected: virtual void runJob() noexcept override; virtual void addRawHeader(const std::string &key, const std::string &value) final; @@ -116,6 +118,8 @@ class AbstractNetworkJob : public AbstractJob { static bool isManagedError(ExitCode exitCode, ExitCause exitCause) noexcept; std::unordered_map _rawHeaders; + + bool _downloadImpossible {false}; }; } // namespace KDC diff --git a/src/libsyncengine/propagation/executor/executorworker.cpp b/src/libsyncengine/propagation/executor/executorworker.cpp index a9408830d..42d273b74 100644 --- a/src/libsyncengine/propagation/executor/executorworker.cpp +++ b/src/libsyncengine/propagation/executor/executorworker.cpp @@ -1622,8 +1622,16 @@ bool ExecutorWorker::deleteFinishedAsyncJobs() { return !hasError; } -bool ExecutorWorker::handleManagedBackError(ExitCause jobExitCause, SyncOpPtr syncOp, bool isInconsistencyIssue) { +bool ExecutorWorker::handleManagedBackError(ExitCause jobExitCause, SyncOpPtr syncOp, bool isInconsistencyIssue, bool downloadImpossible) { _executorExitCode = ExitCodeOk; + + if (jobExitCause == ExitCauseNotFound && !downloadImpossible) { + // The operation failed because the destination does not exist anymore + _executorExitCode = ExitCodeDataError; + LOG_DEBUG(_logger, "Destination does not exist anymore, restarting sync."); + return false; + } + if (jobExitCause == ExitCauseQuotaExceeded) { _syncPal->pause(); } else { @@ -1693,13 +1701,13 @@ bool ExecutorWorker::handleFinishedJob(std::shared_ptr job, SyncOpP if (syncOp->correspondingNode() && syncOp->correspondingNode()->id()) remoteNodeId = *syncOp->correspondingNode()->id(); } + auto networkJob(std::dynamic_pointer_cast(job)); if (const bool isInconsistencyIssue = job->exitCause() == ExitCauseInvalidName; job->exitCode() == ExitCodeBackError && details::isManagedBackError(job->exitCause())) { - return handleManagedBackError(job->exitCause(), syncOp, isInconsistencyIssue); + return handleManagedBackError(job->exitCause(), syncOp, isInconsistencyIssue, networkJob->isDownloadImpossible()); } if (job->exitCode() != ExitCodeOk) { - auto networkJob(std::dynamic_pointer_cast(job)); if (networkJob && (networkJob->getStatusCode() == Poco::Net::HTTPResponse::HTTP_FORBIDDEN || networkJob->getStatusCode() == Poco::Net::HTTPResponse::HTTP_CONFLICT)) { handleForbiddenAction(syncOp, relativeLocalPath); diff --git a/src/libsyncengine/propagation/executor/executorworker.h b/src/libsyncengine/propagation/executor/executorworker.h index 4481c8097..b13c0db6e 100644 --- a/src/libsyncengine/propagation/executor/executorworker.h +++ b/src/libsyncengine/propagation/executor/executorworker.h @@ -70,7 +70,7 @@ class ExecutorWorker : public OperationProcessor { void waitForAllJobsToFinish(bool &hasError); bool deleteFinishedAsyncJobs(); - bool handleManagedBackError(ExitCause jobExitCause, SyncOpPtr syncOp, bool isInconsistencyIssue); + bool handleManagedBackError(ExitCause jobExitCause, SyncOpPtr syncOp, bool isInconsistencyIssue, bool downloadImpossible); bool handleFinishedJob(std::shared_ptr job, SyncOpPtr syncOp, const SyncPath &relativeLocalPath); void handleForbiddenAction(SyncOpPtr syncOp, const SyncPath &relativeLocalPath); void sendProgress();