浏览代码

Check result of setPinState()

Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
Felix Weilbach 4 年之前
父节点
当前提交
d72f7e9109

+ 2 - 1
src/csync/vio/csync_vio_local_unix.cpp

@@ -124,7 +124,8 @@ std::unique_ptr<csync_file_stat_t> csync_vio_local_readdir(csync_vio_handle_t *h
   if (vfs) {
       // Directly modifies file_stat->type.
       // We can ignore the return value since we're done here anyway.
-      vfs->statTypeVirtualFile(file_stat.get(), &handle->path);
+      const auto result = vfs->statTypeVirtualFile(file_stat.get(), &handle->path);
+      Q_UNUSED(result);
   }
 
   return file_stat;

+ 6 - 2
src/gui/accountsettings.cpp

@@ -826,7 +826,9 @@ void AccountSettings::slotEnableVfsCurrentFolder()
             folder->setRootPinState(PinState::Unspecified);
             for (const auto &entry : oldBlacklist) {
                 folder->journalDb()->schedulePathForRemoteDiscovery(entry);
-                folder->vfs().setPinState(entry, PinState::OnlineOnly);
+                if (!folder->vfs().setPinState(entry, PinState::OnlineOnly)) {
+                    qCWarning(lcAccountSettings) << "Could not set pin state of" << entry << "to online only";
+                }
             }
             folder->slotNextSyncFullLocalDiscovery();
 
@@ -932,7 +934,9 @@ void AccountSettings::slotSetSubFolderAvailability(Folder *folder, const QString
     Q_ASSERT(!path.endsWith('/'));
 
     // Update the pin state on all items
-    folder->vfs().setPinState(path, state);
+    if (!folder->vfs().setPinState(path, state)) {
+        qCWarning(lcAccountSettings) << "Could not set pin state of" << path << "to" << state;
+    }
 
     // Trigger sync
     folder->schedulePathForLocalDiscovery(path);

+ 6 - 2
src/gui/folder.cpp

@@ -636,7 +636,9 @@ void Folder::implicitlyHydrateFile(const QString &relativepath)
     // (suffix-virtual file's pin state is stored at the hydrated path)
     const auto pin = _vfs->pinState(relativepath);
     if (pin && *pin == PinState::OnlineOnly) {
-        _vfs->setPinState(relativepath, PinState::Unspecified);
+        if (!_vfs->setPinState(relativepath, PinState::Unspecified)) {
+            qCWarning(lcFolder) << "Could not set pin state of" << relativepath << "to unspecified";
+        }
     }
 
     // Add to local discovery
@@ -675,7 +677,9 @@ void Folder::setVirtualFilesEnabled(bool enabled)
 
 void Folder::setRootPinState(PinState state)
 {
-    _vfs->setPinState(QString(), state);
+    if (!_vfs->setPinState(QString(), state)) {
+        qCWarning(lcFolder) << "Could not set root pin state of" << _definition.alias;
+    }
 
     // We don't actually need discovery, but it's important to recurse
     // into all folders, so the changes can be applied.

+ 6 - 2
src/gui/socketapi.cpp

@@ -796,7 +796,9 @@ void SocketApi::command_MAKE_AVAILABLE_LOCALLY(const QString &filesArg, SocketLi
             continue;
 
         // Update the pin state on all items
-        data.folder->vfs().setPinState(data.folderRelativePath, PinState::AlwaysLocal);
+        if (!data.folder->vfs().setPinState(data.folderRelativePath, PinState::AlwaysLocal)) {
+            qCWarning(lcSocketApi) << "Could not set pin state of" << data.folderRelativePath << "to always local";
+        }
 
         // Trigger sync
         data.folder->schedulePathForLocalDiscovery(data.folderRelativePath);
@@ -815,7 +817,9 @@ void SocketApi::command_MAKE_ONLINE_ONLY(const QString &filesArg, SocketListener
             continue;
 
         // Update the pin state on all items
-        data.folder->vfs().setPinState(data.folderRelativePath, PinState::OnlineOnly);
+        if (!data.folder->vfs().setPinState(data.folderRelativePath, PinState::OnlineOnly)) {
+            qCWarning(lcSocketApi) << "Could not set pin state of" << data.folderRelativePath << "to online only";
+        }
 
         // Trigger sync
         data.folder->schedulePathForLocalDiscovery(data.folderRelativePath);

+ 9 - 3
src/libsync/propagatedownload.cpp

@@ -1079,15 +1079,21 @@ void PropagateDownloadFile::downloadFinished()
             // Move the pin state to the new location
             auto pin = propagator()->_journal->internalPinStates().rawForPath(virtualFile.toUtf8());
             if (pin && *pin != PinState::Inherited) {
-                vfs->setPinState(_item->_file, *pin);
-                vfs->setPinState(virtualFile, PinState::Inherited);
+                if (!vfs->setPinState(_item->_file, *pin)) {
+                    qCWarning(lcPropagateDownload) << "Could not set pin state of" << _item->_file;
+                }
+                if (!vfs->setPinState(virtualFile, PinState::Inherited)) {
+                    qCWarning(lcPropagateDownload) << "Could not set pin state of" << virtualFile << " to inherited";
+                }
             }
         }
 
         // Ensure the pin state isn't contradictory
         auto pin = vfs->pinState(_item->_file);
         if (pin && *pin == PinState::OnlineOnly)
-            vfs->setPinState(_item->_file, PinState::Unspecified);
+            if (!vfs->setPinState(_item->_file, PinState::Unspecified)) {
+                qCWarning(lcPropagateDownload) << "Could not set pin state of" << _item->_file << "to unspecified";
+            }
     }
 
     updateMetadata(isConflict);

+ 3 - 1
src/libsync/propagateremotemove.cpp

@@ -239,7 +239,9 @@ void PropagateRemoteMove::finalize()
 
     // Delete old db data.
     propagator()->_journal->deleteFileRecord(_item->_originalFile);
-    vfs->setPinState(_item->_originalFile, PinState::Inherited);
+    if (!vfs->setPinState(_item->_originalFile, PinState::Inherited)) {
+        qCWarning(lcPropagateRemoteMove) << "Could not set pin state of" << _item->_originalFile << "to inherited";
+    }
 
     SyncFileItem newItem(*_item);
     newItem._type = _item->_type;

+ 3 - 1
src/libsync/propagateupload.cpp

@@ -781,7 +781,9 @@ void PropagateUploadFileCommon::finalize()
         auto &vfs = propagator()->syncOptions()._vfs;
         const auto pin = vfs->pinState(_item->_file);
         if (pin && *pin == PinState::OnlineOnly) {
-            vfs->setPinState(_item->_file, PinState::Unspecified);
+            if (!vfs->setPinState(_item->_file, PinState::Unspecified)) {
+                qCWarning(lcPropagateUpload) << "Could not set pin state of" << _item->_file << "to unspecified";
+            }
         }
     }
 

+ 3 - 1
src/libsync/propagatorjobs.cpp

@@ -248,7 +248,9 @@ void PropagateLocalRename::start()
 
     auto &vfs = propagator()->syncOptions()._vfs;
     auto pinState = vfs->pinState(_item->_originalFile);
-    vfs->setPinState(_item->_originalFile, PinState::Inherited);
+    if (!vfs->setPinState(_item->_originalFile, PinState::Inherited)) {
+        qCWarning(lcPropagateLocalRename) << "Could not set pin state of" << _item->_originalFile << "to inherited";
+    }
 
     const auto oldFile = _item->_file;
 

+ 6 - 6
test/testsyncvirtualfiles.cpp

@@ -1211,8 +1211,8 @@ private slots:
         QCOMPARE(*vfs->availability("local"), VfsItemAvailability::Mixed);
         QCOMPARE(*vfs->availability("online"), VfsItemAvailability::Mixed);
 
-        vfs->setPinState("local", PinState::AlwaysLocal);
-        vfs->setPinState("online", PinState::OnlineOnly);
+        QVERIFY(vfs->setPinState("local", PinState::AlwaysLocal));
+        QVERIFY(vfs->setPinState("online", PinState::OnlineOnly));
         QVERIFY(fakeFolder.syncOnce());
 
         QCOMPARE(*vfs->availability("online"), VfsItemAvailability::OnlineOnly);
@@ -1293,13 +1293,13 @@ private slots:
         QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename" DVSUFFIX), PinState::OnlineOnly);
 
         // When a file is hydrated or dehydrated due to pin state it retains its pin state
-        vfs->setPinState("onlinerenamed2/file1rename" DVSUFFIX, PinState::AlwaysLocal);
+        QVERIFY(vfs->setPinState("onlinerenamed2/file1rename" DVSUFFIX, PinState::AlwaysLocal));
         QVERIFY(fakeFolder.syncOnce());
         QVERIFY(fakeFolder.currentLocalState().find("onlinerenamed2/file1rename"));
         QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::AlwaysLocal);
 
-        vfs->setPinState("onlinerenamed2", PinState::Unspecified);
-        vfs->setPinState("onlinerenamed2/file1rename", PinState::OnlineOnly);
+        QVERIFY(vfs->setPinState("onlinerenamed2", PinState::Unspecified));
+        QVERIFY(vfs->setPinState("onlinerenamed2/file1rename", PinState::OnlineOnly));
         QVERIFY(fakeFolder.syncOnce());
         QVERIFY(fakeFolder.currentLocalState().find("onlinerenamed2/file1rename" DVSUFFIX));
         QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename" DVSUFFIX), PinState::OnlineOnly);
@@ -1376,7 +1376,7 @@ private slots:
 
         cleanup();
         // Dehydrate
-        vfs->setPinState(QString(), PinState::OnlineOnly);
+        QVERIFY(vfs->setPinState(QString(), PinState::OnlineOnly));
         QVERIFY(!fakeFolder.syncOnce());
 
         QVERIFY(itemInstruction(completeSpy, "A/igno" DVSUFFIX, CSYNC_INSTRUCTION_IGNORE));

+ 5 - 5
test/testsyncxattr.cpp

@@ -956,8 +956,8 @@ private slots:
         QCOMPARE(*vfs->availability("local"), VfsItemAvailability::Mixed);
         QCOMPARE(*vfs->availability("online"), VfsItemAvailability::Mixed);
 
-        vfs->setPinState("local", PinState::AlwaysLocal);
-        vfs->setPinState("online", PinState::OnlineOnly);
+        QVERIFY(vfs->setPinState("local", PinState::AlwaysLocal));
+        QVERIFY(vfs->setPinState("online", PinState::OnlineOnly));
         QVERIFY(fakeFolder.syncOnce());
 
         QCOMPARE(*vfs->availability("online"), VfsItemAvailability::OnlineOnly);
@@ -1037,13 +1037,13 @@ private slots:
         QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::OnlineOnly);
 
         // When a file is hydrated or dehydrated due to pin state it retains its pin state
-        vfs->setPinState("onlinerenamed2/file1rename", PinState::AlwaysLocal);
+        QVERIFY(vfs->setPinState("onlinerenamed2/file1rename", PinState::AlwaysLocal));
         QVERIFY(fakeFolder.syncOnce());
         QVERIFY(fakeFolder.currentLocalState().find("onlinerenamed2/file1rename"));
         QCOMPARE(*vfs->pinState("onlinerenamed2/file1rename"), PinState::AlwaysLocal);
 
-        vfs->setPinState("onlinerenamed2", PinState::Unspecified);
-        vfs->setPinState("onlinerenamed2/file1rename", PinState::OnlineOnly);
+        QVERIFY(vfs->setPinState("onlinerenamed2", PinState::Unspecified));
+        QVERIFY(vfs->setPinState("onlinerenamed2/file1rename", PinState::OnlineOnly));
         QVERIFY(fakeFolder.syncOnce());
 
         XAVERIFY_VIRTUAL(fakeFolder, "onlinerenamed2/file1rename");