Skip to content

Commit

Permalink
Merge pull request nextcloud#6294 from nextcloud/backport/6285/stable…
Browse files Browse the repository at this point in the history
…-3.11

[stable-3.11] Bugfix. Do not treat item type change as metadata update.
  • Loading branch information
mgallien authored Dec 13, 2023
2 parents 450b2f1 + 9c90805 commit efd0b53
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,19 +983,21 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
bool serverModified = item->_instruction == CSYNC_INSTRUCTION_NEW || item->_instruction == CSYNC_INSTRUCTION_SYNC
|| item->_instruction == CSYNC_INSTRUCTION_RENAME || item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE;

const auto isTypeChange = item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE;

qCDebug(lcDisco) << "File" << item->_file << "- servermodified:" << serverModified
<< "noServerEntry:" << noServerEntry;

// Decay server modifications to UPDATE_METADATA if the local virtual exists
bool hasLocalVirtual = localEntry.isVirtualFile || (_queryLocal == ParentNotChanged && dbEntry.isVirtualFile());
bool virtualFileDownload = item->_type == ItemTypeVirtualFileDownload;
if (serverModified && !virtualFileDownload && hasLocalVirtual) {
if (serverModified && !isTypeChange && !virtualFileDownload && hasLocalVirtual) {
item->_instruction = CSYNC_INSTRUCTION_UPDATE_METADATA;
serverModified = false;
item->_type = ItemTypeVirtualFile;
}

if (dbEntry.isVirtualFile() && (!localEntry.isValid() || localEntry.isVirtualFile) && !virtualFileDownload) {
if (dbEntry.isVirtualFile() && (!localEntry.isValid() || localEntry.isVirtualFile) && !virtualFileDownload && !isTypeChange) {
item->_type = ItemTypeVirtualFile;
}

Expand Down
26 changes: 26 additions & 0 deletions test/testsynccfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,32 @@ private slots:
QVERIFY(fakeFolder.syncOnce());
QVERIFY(itemInstruction(completeSpy, "A", CSYNC_INSTRUCTION_NONE));
}

void testRemoteTypeChangeExistingLocalMustGetRemoved()
{
FakeFolder fakeFolder{FileInfo{}};
setupVfs(fakeFolder);

// test file change to directory on remote
fakeFolder.remoteModifier().mkdir("a");
fakeFolder.remoteModifier().insert("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTFILE");
fakeFolder.remoteModifier().mkdir("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());


// test directory change to file on remote
fakeFolder.remoteModifier().mkdir("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTDIR");
fakeFolder.remoteModifier().insert("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
};

QTEST_GUILESS_MAIN(TestSyncCfApi)
Expand Down
24 changes: 24 additions & 0 deletions test/testsyncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,30 @@ private slots:
QVERIFY(itemDidCompleteSuccessfully(completeSpy, "A/abcdęfg.txt"));
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testRemoteTypeChangeExistingLocalMustGetRemoved()
{
FakeFolder fakeFolder{FileInfo{}};

// test file change to directory on remote
fakeFolder.remoteModifier().mkdir("a");
fakeFolder.remoteModifier().insert("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTFILE");
fakeFolder.remoteModifier().mkdir("a/TESTFILE");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

// test directory change to file on remote
fakeFolder.remoteModifier().mkdir("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());

fakeFolder.remoteModifier().remove("a/TESTDIR");
fakeFolder.remoteModifier().insert("a/TESTDIR");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
};

QTEST_GUILESS_MAIN(TestSyncEngine)
Expand Down

0 comments on commit efd0b53

Please sign in to comment.