From fb21eb55cf6d9f2a51954c9aec117a6b9ac47a50 Mon Sep 17 00:00:00 2001 From: Dries Mys Date: Sun, 23 Jul 2023 00:01:45 +0200 Subject: [PATCH] Alter testUnexpectedNonPlaceholder to better reflect the actual use case Signed-off-by: Dries Mys --- src/libsync/vfs/cfapi/cfapiwrapper.cpp | 2 +- test/testsynccfapi.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index 922e899d5..ac9e90b9e 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -865,7 +865,7 @@ OCC::Result OCC::CfApiWrapper::co OCC::Result OCC::CfApiWrapper::revertPlaceholder(const QString &path) { - const qint64 result = CfRevertPlaceholder(handleForPath(path).get(), CF_REVERT_FLAG_NONE, nullptr); + const auto result = CfRevertPlaceholder(handleForPath(path).get(), CF_REVERT_FLAG_NONE, nullptr); if (result != S_OK) { qCWarning(lcCfApiWrapper) << "Couldn't revert placeholder for" << path << ":" << QString::fromWCharArray(_com_error(result).ErrorMessage()); return {"Couldn't revert placeholder"}; diff --git a/test/testsynccfapi.cpp b/test/testsynccfapi.cpp index f3efd7624..cc1a023f5 100644 --- a/test/testsynccfapi.cpp +++ b/test/testsynccfapi.cpp @@ -120,7 +120,7 @@ private slots: QTest::newRow("skip local discovery") << false; } - void testUnexpectedNonPlaceholder() + void testReplaceFileByIdenticalFile() { FakeFolder fakeFolder{FileInfo{}}; auto vfs = setupVfs(fakeFolder); @@ -129,13 +129,16 @@ private slots: // Create a new local (non-placeholder) file fakeFolder.localModifier().insert("file0"); fakeFolder.localModifier().insert("file1"); + CopyFile(QString(fakeFolder.localPath() + "file1").toStdWString().data(), QString(fakeFolder.localPath() + "file2").toStdWString().data(), false); QVERIFY(!vfs->pinState("file0").isValid()); QVERIFY(!vfs->pinState("file1").isValid()); + QVERIFY(!vfs->pinState("file2").isValid()); // Sync the files: files should be converted to placeholder files QVERIFY(fakeFolder.syncOnce()); QVERIFY(vfs->pinState("file0").isValid()); QVERIFY(vfs->pinState("file1").isValid()); + QVERIFY(vfs->pinState("file2").isValid()); // Sync again to ensure items are fully synced, otherwise test may succeed due to those pending changes. QVERIFY(fakeFolder.syncOnce()); @@ -143,15 +146,17 @@ private slots: QVERIFY(fakeFolder.syncOnce()); QVERIFY(completeSpy.isEmpty()); - // Convert to regular file (may occur when file is replaced by another one) - QVERIFY(cfapi::revertPlaceholder(fakeFolder.localPath() + "file1")); + // Replace file1 by identical file2: Windows will convert file1 to a regular (non-placeholder) file again. + CopyFile(QString(fakeFolder.localPath() + "file2").toStdWString().data(), QString(fakeFolder.localPath() + "file1").toStdWString().data(), false); QVERIFY(vfs->pinState("file0").isValid()); QVERIFY(!vfs->pinState("file1").isValid()); + QVERIFY(vfs->pinState("file2").isValid()); // Sync again: file should be correctly converted to placeholders QVERIFY(fakeFolder.syncOnce()); QVERIFY(vfs->pinState("file0").isValid()); QVERIFY(vfs->pinState("file1").isValid()); + QVERIFY(vfs->pinState("file2").isValid()); } void testReplaceOnlineOnlyFile() -- 2.30.2