Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance FileAccessError on a parent detection. #411

Merged
merged 10 commits into from
Dec 6, 2024
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)) {
ClementKunz marked this conversation as resolved.
Show resolved Hide resolved
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;
herve-er marked this conversation as resolved.
Show resolved Hide resolved
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