allow dehydrating pinned LNK files
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 16 Dec 2024 13:02:02 +0000 (14:02 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 16 Dec 2024 15:19:13 +0000 (16:19 +0100)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/vfs/cfapi/cfapiwrapper.cpp
test/testsynccfapi.cpp

index ed214b88f9d780b066a96a5193750a7aa2de0f4b..99100dde584baef408d8f03df18d61bff92b3a42 100644 (file)
@@ -334,6 +334,8 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> 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<OCC::Vfs::ConvertToPlaceholderResult, QString> 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,6 +908,8 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::de
 
     const auto info = findPlaceholderInfo(path);
     if (info) {
+        setPinState(path, OCC::PinState::OnlineOnly, OCC::CfApiWrapper::NoRecurse);
+
         CF_FILE_RANGE dehydrationRange;
         dehydrationRange.StartingOffset.QuadPart = 0;
         dehydrationRange.Length.QuadPart = size;
@@ -919,7 +923,6 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::de
                                                   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());
index a306bc44e2b25d8903131ba25c1f6dfd35e143c2..d1ef2994e2866b71310889c5ac4760970355a435 100644 (file)
@@ -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());