diff --git a/src/libsyncengine/syncpal/syncpal.cpp b/src/libsyncengine/syncpal/syncpal.cpp index 89d72f83d..75f47859a 100644 --- a/src/libsyncengine/syncpal/syncpal.cpp +++ b/src/libsyncengine/syncpal/syncpal.cpp @@ -48,6 +48,7 @@ #include "jobs/jobmanager.h" #include "libcommon/utility/utility.h" #include "libcommonserver/utility/utility.h" +#include "libcommonserver/io/iohelper.h" #include "tmpblacklistmanager.h" #define SYNCPAL_NEW_ERROR_MSG "Failed to create SyncPal instance!" @@ -1470,33 +1471,44 @@ ExitInfo SyncPal::handleAccessDeniedItem(const SyncPath &relativePath, ExitCause NodeId localNodeId; if (localNodeId = snapshot(ReplicaSide::Local)->itemId(relativePath); localNodeId.empty()) { - // The file does not exit yet on local file system, or we do not have sufficient right on a parent folder. - LOGW_DEBUG(_logger, L"Item " << Utility::formatSyncPath(relativePath) - << L"is not present local file system, blacklisting the parent item."); - return handleAccessDeniedItem(relativePath.parent_path(), cause); + SyncPath absolutePath = localPath() / relativePath; + if (!IoHelper::getNodeId(absolutePath, localNodeId)) { + bool exists = false; + IoError ioError = IoError::Success; + if (!IoHelper::checkIfPathExists(absolutePath, exists, ioError)) { + LOGW_WARN(_logger, L"IoHelper::checkIfPathExists failed with: " << Utility::formatIoError(absolutePath, ioError)); + return ExitCode::SystemError; + } + if (ioError == IoError::AccessDenied) { // A parent of the file does not have sufficient right + LOGW_DEBUG(_logger, L"A parent of " << Utility::formatSyncPath(relativePath) + << L"does not have sufficient right, blacklisting the parent item."); + return handleAccessDeniedItem(relativePath.parent_path(), cause); + } + } } LOGW_SYNCPAL_DEBUG(_logger, L"Item " << Utility::formatSyncPath(relativePath) << L" (NodeId: " << Utility::s2ws(localNodeId) << L" is blacklisted temporarily because of a denied access."); - NodeId correspondingNodeId; - correspondingNodeId = snapshot(ReplicaSide::Remote)->itemId(relativePath); - if (bool found; correspondingNodeId.empty() && - !_syncDb->correspondingNodeId(ReplicaSide::Local, localNodeId, correspondingNodeId, found)) { + NodeId remoteNodeId = snapshot(ReplicaSide::Remote)->itemId(relativePath); + if (bool found; remoteNodeId.empty() && !localNodeId.empty() && + !_syncDb->correspondingNodeId(ReplicaSide::Local, localNodeId, remoteNodeId, found)) { LOG_SYNCPAL_WARN(_logger, "Error in SyncDb::correspondingNodeId"); return {ExitCode::DbError, ExitCause::Unknown}; } // Blacklist the item - _tmpBlacklistManager->blacklistItem(localNodeId, relativePath, ReplicaSide::Local); - if (!updateTree(ReplicaSide::Local)->deleteNode(localNodeId)) { - LOGW_SYNCPAL_WARN(_logger, L"Error in UpdateTree::deleteNode: " << Utility::formatSyncPath(relativePath)); + if (!localNodeId.empty()) { + _tmpBlacklistManager->blacklistItem(localNodeId, relativePath, ReplicaSide::Local); + if (!updateTree(ReplicaSide::Local)->deleteNode(localNodeId)) { + LOGW_SYNCPAL_WARN(_logger, L"Error in UpdateTree::deleteNode: " << Utility::formatSyncPath(relativePath)); + } } - if (!correspondingNodeId.empty()) { - _tmpBlacklistManager->blacklistItem(correspondingNodeId, relativePath, ReplicaSide::Remote); - if (!updateTree(ReplicaSide::Remote)->deleteNode(correspondingNodeId)) { + if (!remoteNodeId.empty()) { + _tmpBlacklistManager->blacklistItem(remoteNodeId, relativePath, ReplicaSide::Remote); + if (!updateTree(ReplicaSide::Remote)->deleteNode(remoteNodeId)) { LOGW_SYNCPAL_WARN(_logger, L"Error in UpdateTree::deleteNode: " << Utility::formatSyncPath(relativePath)); } }