From 321c583b6942bb425793f399f6958d42b32cabaf Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 16 Dec 2024 14:02:02 +0100 Subject: [PATCH 1/2] allow dehydrating pinned LNK files Signed-off-by: Matthieu Gallien --- src/libsync/vfs/cfapi/cfapiwrapper.cpp | 29 ++++++++++++++++---------- test/testsynccfapi.cpp | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index c1d13479f69e5..99100dde584ba 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -334,6 +334,8 @@ OCC::Result updatePlaceholderStat OCC::Utility::UnixTimeToLargeIntegerFiletime(modtime, &metadata.BasicInfo.ChangeTime); metadata.BasicInfo.FileAttributes = 0; + OCC::CfApiWrapper::setPinState(path, OCC::PinState::Unspecified, OCC::CfApiWrapper::SetPinRecurseMode::NoRecurse); + qCInfo(lcCfApiWrapper) << "updatePlaceholderState" << path << modtime; const qint64 result = CfUpdatePlaceholder(OCC::CfApiWrapper::handleForPath(path).get(), updateType == CfApiUpdateMetadataType::AllMetadata ? &metadata : nullptr, fileIdentity.data(), sizeToDWORD(fileIdentitySize), @@ -345,7 +347,7 @@ OCC::Result updatePlaceholderStat return errorMessage; } - // Pin state tends to be lost on updates, so restore it every time + // Pin state tends to be lost on updates, so restore it every time if (!setPinState(path, previousPinState, OCC::CfApiWrapper::NoRecurse)) { return { "Couldn't restore pin state" }; } @@ -906,16 +908,21 @@ OCC::Result OCC::CfApiWrapper::de const auto info = findPlaceholderInfo(path); if (info) { - LARGE_INTEGER largeStart, largeSize; - largeStart.QuadPart = 0; - largeSize.QuadPart = size; - - const qint64 result = CfDehydratePlaceholder(handleForPath(path).get(), - largeStart, - largeSize, - CF_DEHYDRATE_FLAG_NONE, - 0); - + setPinState(path, OCC::PinState::OnlineOnly, OCC::CfApiWrapper::NoRecurse); + + CF_FILE_RANGE dehydrationRange; + dehydrationRange.StartingOffset.QuadPart = 0; + dehydrationRange.Length.QuadPart = size; + + const qint64 result = CfUpdatePlaceholder(handleForPath(path).get(), + nullptr, + fileIdentity.data(), + sizeToDWORD(fileIdentitySize), + &dehydrationRange, + 1, + CF_UPDATE_FLAG_MARK_IN_SYNC | CF_UPDATE_FLAG_DEHYDRATE, + nullptr, + nullptr); if (result != S_OK) { const auto errorMessage = createErrorMessageForPlaceholderUpdateAndCreate(path, "Couldn't update placeholder info"); qCWarning(lcCfApiWrapper) << errorMessage << path << ":" << QString::fromWCharArray(_com_error(result).ErrorMessage()); diff --git a/test/testsynccfapi.cpp b/test/testsynccfapi.cpp index a306bc44e2b25..d1ef2994e2866 100644 --- a/test/testsynccfapi.cpp +++ b/test/testsynccfapi.cpp @@ -1210,7 +1210,7 @@ private slots: CFVERIFY_VIRTUAL(fakeFolder, "local/file1"); QCOMPARE(*vfs->pinState("online/file1"), PinState::Unspecified); - QCOMPARE(*vfs->pinState("local/file1"), PinState::Unspecified); + QCOMPARE(*vfs->pinState("local/file1"), PinState::OnlineOnly); // no change on another sync QVERIFY(fakeFolder.syncOnce()); From 5d2ee18886dda58c59a3bea6b409d0c386d39fa5 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 16 Dec 2024 14:02:38 +0100 Subject: [PATCH 2/2] remove deprecated API Signed-off-by: Matthieu Gallien --- src/libsync/vfs/cfapi/cfapiwrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/vfs/cfapi/cfapiwrapper.cpp b/src/libsync/vfs/cfapi/cfapiwrapper.cpp index 99100dde584ba..5828cd3a048d2 100644 --- a/src/libsync/vfs/cfapi/cfapiwrapper.cpp +++ b/src/libsync/vfs/cfapi/cfapiwrapper.cpp @@ -593,7 +593,7 @@ bool createSyncRootRegistryKeys(const QString &providerName, const QString &fold { providerSyncRootIdRegistryKey, QStringLiteral("NamespaceCLSID"), REG_SZ, QString(navigationPaneClsid)} }; - for (const auto ®istryKeyToSet : qAsConst(registryKeysToSet)) { + for (const auto ®istryKeyToSet : std::as_const(registryKeysToSet)) { if (!OCC::Utility::registrySetKeyValue(HKEY_LOCAL_MACHINE, registryKeyToSet.subKey, registryKeyToSet.valueName, registryKeyToSet.type, registryKeyToSet.value)) { qCWarning(lcCfApiWrapper) << "Failed to set Registry keys for shell integration. Progress bar will not work."; const auto deleteKeyResult = OCC::Utility::registryDeleteKeyTree(HKEY_LOCAL_MACHINE, providerSyncRootIdRegistryKey);