Skip to content

Commit

Permalink
Alter testUnexpectedNonPlaceholder to better reflect the actual use case
Browse files Browse the repository at this point in the history
Signed-off-by: Dries Mys <[email protected]>
  • Loading branch information
m7913d authored and mgallien committed Jul 24, 2023
1 parent 507bc6c commit 52906d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/libsync/vfs/cfapi/cfapiwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::co

OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> 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"};
Expand Down
11 changes: 8 additions & 3 deletions test/testsynccfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private slots:
QTest::newRow("skip local discovery") << false;
}

void testUnexpectedNonPlaceholder()
void testReplaceFileByIdenticalFile()
{
FakeFolder fakeFolder{FileInfo{}};
auto vfs = setupVfs(fakeFolder);
Expand All @@ -129,29 +129,34 @@ 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());
completeSpy.clear();
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()
Expand Down

0 comments on commit 52906d8

Please sign in to comment.