From 3831d8b462aa7f04e67fc31b80bb226fbf500936 Mon Sep 17 00:00:00 2001 From: alex-z Date: Thu, 14 Sep 2023 13:14:16 +0200 Subject: [PATCH 1/3] Do not attempt to convert .lnk files to placeholder. Also do not modify folders' metadata. Signed-off-by: alex-z --- src/libsync/discovery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index ee694c2bb0315..e33dda14d4387 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -1101,7 +1101,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo( item->_type = ItemTypeVirtualFileDehydration; } else if (!serverModified && (dbEntry._inode != localEntry.inode - || localEntry.isMetadataMissing + || (localEntry.isMetadataMissing && item->_type == ItemTypeFile && !FileSystem::isLnkFile(item->_file)) || _discoveryData->_syncOptions._vfs->needsMetadataUpdate(*item))) { item->_instruction = CSYNC_INSTRUCTION_UPDATE_METADATA; item->_direction = SyncFileItem::Down; From cc99b0ae45068eed06b5e096e872b667c477864c Mon Sep 17 00:00:00 2001 From: alex-z Date: Thu, 14 Sep 2023 13:17:31 +0200 Subject: [PATCH 2/3] Remove unused function 'revertPlaceholder'. Signed-off-by: alex-z --- src/libsync/vfs/cfapi/cfapiwrapper.cpp | 11 ----------- src/libsync/vfs/cfapi/cfapiwrapper.h | 1 - 2 files changed, 12 deletions(-) diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index ac9e90b9ed6c3..ee729896300a5 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -862,14 +862,3 @@ OCC::Result OCC::CfApiWrapper::co return stateResult; } } - -OCC::Result OCC::CfApiWrapper::revertPlaceholder(const QString &path) -{ - 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"}; - } - - return OCC::Vfs::ConvertToPlaceholderResult::Ok; -} diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.h b/src/libsync/vfs/cfapi/cfapiwrapper.h index ee5c20216dcbd..10cb51aaa82bb 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.h +++ b/src/libsync/vfs/cfapi/cfapiwrapper.h @@ -97,7 +97,6 @@ NEXTCLOUD_CFAPI_EXPORT Result createPlaceholderInfo(const QString NEXTCLOUD_CFAPI_EXPORT Result updatePlaceholderInfo(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath = QString()); NEXTCLOUD_CFAPI_EXPORT Result convertToPlaceholder(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId, const QString &replacesPath); NEXTCLOUD_CFAPI_EXPORT Result dehydratePlaceholder(const QString &path, time_t modtime, qint64 size, const QByteArray &fileId); -NEXTCLOUD_CFAPI_EXPORT Result revertPlaceholder(const QString &path); } From d26fc34c5c766f1215ae9bc995bd6f87e29b985d Mon Sep 17 00:00:00 2001 From: alex-z Date: Thu, 14 Sep 2023 15:04:46 +0200 Subject: [PATCH 3/3] Tests for placeholder file metadata update. Signed-off-by: alex-z --- test/testsynccfapi.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/testsynccfapi.cpp b/test/testsynccfapi.cpp index fc6602dcd77d5..0397bc0fc99ba 100644 --- a/test/testsynccfapi.cpp +++ b/test/testsynccfapi.cpp @@ -1354,6 +1354,36 @@ private slots: const auto localFileLocked = QFileInfo{fakeFolder.localPath() + u"A/a1"}; QVERIFY(!localFileLocked.isWritable()); } + + void testLinkFileDoesNotConvertToPlaceholder() + { + // inspired by GH issue #6041 + FakeFolder fakeFolder{FileInfo{}}; + auto vfs = setupVfs(fakeFolder); + + // Create a Windows shotcut (.lnk) file + fakeFolder.remoteModifier().insert("linkfile.lnk"); + + QVERIFY(fakeFolder.syncOnce()); + ItemCompletedSpy completeSpy(fakeFolder); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(!vfs->pinState("linkfile.lnk").isValid() || vfs->pinState("linkfile.lnk").get() == PinState::Excluded); + QVERIFY(itemInstruction(completeSpy, "linkfile.lnk", CSYNC_INSTRUCTION_NONE)); + } + + void testFolderDoesNotUpdatePlaceholderMetadata() + { + FakeFolder fakeFolder{FileInfo{}}; + auto vfs = setupVfs(fakeFolder); + + fakeFolder.remoteModifier().mkdir("A"); + fakeFolder.remoteModifier().insert("A/file"); + + QVERIFY(fakeFolder.syncOnce()); + ItemCompletedSpy completeSpy(fakeFolder); + QVERIFY(fakeFolder.syncOnce()); + QVERIFY(itemInstruction(completeSpy, "A", CSYNC_INSTRUCTION_NONE)); + } }; QTEST_GUILESS_MAIN(TestSyncCfApi)