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

KDESKTOP-1342-Encoding-issue-Remote-edition-leads-to-blacklist-and-deleted-file #378

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,9 @@ ExitCode UpdateTreeWorker::step8CompleteUpdateTree() {

SyncTime lastModified =
_side == ReplicaSide::Local ? dbNode.lastModifiedLocal().value() : dbNode.lastModifiedRemote().value();
SyncName name = dbNode.nameRemote();
std::shared_ptr<Node> newNode =
std::shared_ptr<Node>(new Node(dbNode.nodeId(), _side, name, dbNode.type(), {}, newNodeId, dbNode.created(),
lastModified, dbNode.size(), parentNode));
SyncName name = _side == ReplicaSide::Local ? dbNode.nameLocal() : dbNode.nameRemote();
luc-guyot-infomaniak marked this conversation as resolved.
Show resolved Hide resolved
const auto newNode = std::shared_ptr<Node>(new Node(dbNode.nodeId(), _side, name, dbNode.type(), {}, newNodeId,
dbNode.created(), lastModified, dbNode.size(), parentNode));
if (newNode == nullptr) {
std::cout << "Failed to allocate memory" << std::endl;
LOG_SYNCPAL_ERROR(_logger, "Failed to allocate memory");
Expand Down Expand Up @@ -1476,17 +1475,6 @@ ExitCode UpdateTreeWorker::updateNameFromDbForMoveOp(const std::shared_ptr<Node>
return ExitCode::DataError;
}

if (dbNode.nameLocal() != dbNode.nameRemote()) { // Useless?? Now the local and remote name are always the same
// Check if the file has been renamed locally
if (moveOp->destinationPath().filename() != dbNode.nameLocal()) {
// The file has been renamed locally, propagate the change on remote
node->setName(moveOp->destinationPath().filename().native());
} else {
// The file has been moved but not renamed, keep the names from DB
node->setName(dbNode.nameRemote());
}
}

return ExitCode::Ok;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ void TestUpdateTreeWorker::setUpDbTree() {
├── 5
│ └── 5.1
├── 6
└── 6a
├── 6a
└── 7
*/

time_t tLoc = std::time(0);
Expand Down Expand Up @@ -147,6 +148,13 @@ void TestUpdateTreeWorker::setUpDbTree() {
DbNode nodeFile6a(0, _syncDb->rootNode().nodeId(), Str("File 6a"), Str("File 6a"), "id6a", "id drive 6a", tLoc, tLoc, tDrive,
NodeType::File, 0, std::nullopt);
_syncDb->insertNode(nodeFile6a, dbnodeIdfile6a, constraintError);

// Node with name encoded differently on remote (NFC) and on local (NFD) side
DbNodeId dbnodeIdfile7;
const DbNode nodeFile7(0, _syncDb->rootNode().nodeId(), testhelpers::makeNfdSyncName(), testhelpers::makeNfdSyncName(),
"id7l", "id7r", testhelpers::defaultTime, testhelpers::defaultTime, testhelpers::defaultTime,
NodeType::File, testhelpers::defaultFileSize, std::nullopt);
_syncDb->insertNode(nodeFile7, dbnodeIdfile7, constraintError);
}

void TestUpdateTreeWorker::setUpUpdateTree() {
Expand All @@ -165,7 +173,8 @@ void TestUpdateTreeWorker::setUpUpdateTree() {
│ └── 4.1.1
│ └── 4.1.1.1
├── 6
└── 6a
├── 6a
└── 7
*/
SyncTime createdAt = 1654788079;
SyncTime lastmodified = 1654788079;
Expand Down Expand Up @@ -224,6 +233,12 @@ void TestUpdateTreeWorker::setUpUpdateTree() {
std::shared_ptr<Node>(new Node(dbNodeIdDir, _updateTree->side(), Str("File 6a"), NodeType::File, OperationType::None,
"id6a", createdAt, lastmodified, size, _updateTree->rootNode()));

// Name encoded NFD on local side
_syncDb->dbId(ReplicaSide::Local, NodeId("id7l"), dbNodeIdDir, found);
const auto node7 =
std::make_shared<Node>(dbNodeIdDir, _updateTree->side(), testhelpers::makeNfdSyncName(), NodeType::File,
OperationType::None, "id7l", createdAt, lastmodified, size, _updateTree->rootNode());

_updateTree->init();

CPPUNIT_ASSERT(_updateTree->rootNode()->insertChildren(node1));
Expand All @@ -232,6 +247,7 @@ void TestUpdateTreeWorker::setUpUpdateTree() {
CPPUNIT_ASSERT(_updateTree->rootNode()->insertChildren(node4));
CPPUNIT_ASSERT(_updateTree->rootNode()->insertChildren(node6));
CPPUNIT_ASSERT(_updateTree->rootNode()->insertChildren(node6a));
CPPUNIT_ASSERT(_updateTree->rootNode()->insertChildren(node7));

CPPUNIT_ASSERT(node1->insertChildren(node11));
CPPUNIT_ASSERT(node11->insertChildren(node111));
Expand All @@ -254,6 +270,7 @@ void TestUpdateTreeWorker::setUpUpdateTree() {
_updateTree->insertNode(node4111);
_updateTree->insertNode(node6);
_updateTree->insertNode(node6a);
_updateTree->insertNode(node7);
}

void TestUpdateTreeWorker::testUtilsFunctions() {
Expand Down Expand Up @@ -518,6 +535,9 @@ void TestUpdateTreeWorker::testStep8() {
CPPUNIT_ASSERT(_updateTree->getNodeByPath("Dir 5/File 5.1")->id() == "id51");
CPPUNIT_ASSERT(_updateTree->getNodeByPath("Dir 1/Dir 1.1/File 1.1.2")->id() == "id112");
CPPUNIT_ASSERT(_updateTree->getNodeByPath("Dir 4/Dir 4.1/Dir 4.1.1/File 4.1.1.2")->id() == "id4112");

// Make sure we retrieve the NFD encoded version of the name
CPPUNIT_ASSERT_EQUAL(std::string("id7l"), *_updateTree->getNodeByPath(testhelpers::makeNfdSyncName())->id());
}

void TestUpdateTreeWorker::testClearTreeStep1() {
Expand Down Expand Up @@ -654,7 +674,7 @@ void TestUpdateTreeWorker::testClearTreeStep7() {

void TestUpdateTreeWorker::testClearTreeStep8() {
CPPUNIT_ASSERT_EQUAL(ExitCode::Ok, _updateTreeWorker->step8CompleteUpdateTree());
CPPUNIT_ASSERT(_updateTreeWorker->_updateTree->nodes().size() == 18);
CPPUNIT_ASSERT(_updateTreeWorker->_updateTree->nodes().size() == 19);
}

void TestUpdateTreeWorker::testGetOriginPath() {
Expand Down
Loading