Skip to content

Commit

Permalink
Enhance FileAccessError on a parent detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
herve-er committed Nov 27, 2024
1 parent e11e1c3 commit 1095c5c
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/libsyncengine/syncpal/syncpal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down Expand Up @@ -1459,33 +1460,45 @@ 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;
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));
}
}
Expand Down

0 comments on commit 1095c5c

Please sign in to comment.