Skip to content

Commit

Permalink
Merge pull request #411 from Infomaniak/KDESKTOP-1416-Remaining-black…
Browse files Browse the repository at this point in the history
…listed-issue

Enhance FileAccessError on a parent detection.
  • Loading branch information
ClementKunz authored Dec 6, 2024
2 parents 4bfcfbb + 107be49 commit 33c7d8e
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 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 @@ -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));
}
}
Expand Down

0 comments on commit 33c7d8e

Please sign in to comment.