Do not ignore return values for SyncJournalDB in folder, encryptfolderjob, hydrationj...
authorallexzander <blackslayer4@gmail.com>
Thu, 4 Aug 2022 14:13:59 +0000 (17:13 +0300)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Sat, 17 Sep 2022 07:47:15 +0000 (09:47 +0200)
Signed-off-by: allexzander <blackslayer4@gmail.com>
src/gui/folder.cpp
src/libsync/discovery.cpp
src/libsync/encryptfolderjob.cpp
src/libsync/vfs/cfapi/hydrationjob.cpp
src/libsync/vfs/suffix/vfs_suffix.cpp

index 7229c1ba48d409e0edd8e526bbeb96b984778998..9a50716a1c6bad22f2346e08bc73428eae4ac6f5 100644 (file)
@@ -577,7 +577,9 @@ void Folder::slotWatchedPathChanged(const QString &path, ChangeReason reason)
 
 
     SyncJournalFileRecord record;
-    _journal.getFileRecord(relativePathBytes, &record);
+    if (!_journal.getFileRecord(relativePathBytes, &record)) {
+        qCWarning(lcFolder) << "could not get file from local DB" << relativePathBytes;
+    }
     if (reason != ChangeReason::UnLock) {
         // Check that the mtime/size actually changed or there was
         // an attribute change (pin state) that caused the notification
@@ -613,7 +615,11 @@ void Folder::implicitlyHydrateFile(const QString &relativepath)
 
     // Set in the database that we should download the file
     SyncJournalFileRecord record;
-    _journal.getFileRecord(relativepath.toUtf8(), &record);
+    ;
+    if (!_journal.getFileRecord(relativepath.toUtf8(), &record)) {
+        qCWarning(lcFolder) << "could not get file from local DB" << relativepath;
+        return;
+    }
     if (!record.isValid()) {
         qCInfo(lcFolder) << "Did not find file in db";
         return;
@@ -622,8 +628,14 @@ void Folder::implicitlyHydrateFile(const QString &relativepath)
         qCInfo(lcFolder) << "The file is not virtual";
         return;
     }
+
     record._type = ItemTypeVirtualFileDownload;
-    _journal.setFileRecord(record);
+
+    const auto result = _journal.setFileRecord(record);
+    if (!result) {
+        qCWarning(lcFolder) << "Error when setting the file record to the database" << record._path << result.error();
+        return;
+    }
 
     // Change the file's pin state if it's contradictory to being hydrated
     // (suffix-virtual file's pin state is stored at the hydrated path)
index 4f2dc96108a01fcf3f815d0e90a280ad9d5a89e6..7a59f1fa97cc4e054882982fe9845bc820ea78ef 100644 (file)
@@ -1430,7 +1430,7 @@ void ProcessDirectoryJob::processFileConflict(const SyncFileItemPtr &item, Proce
             rec._checksumHeader = serverEntry.checksumHeader;
             const auto result = _discoveryData->_statedb->setFileRecord(rec);
             if (!result) {
-                qCWarning(lcDisco) << "Error when setting the file record to the database" << result.error();
+                qCWarning(lcDisco) << "Error when setting the file record to the database" << rec._path << result.error();
             }
         }
         return;
index 1a9fc658438b25d61e556a1e7b2cc7f0da22f715..e9a8f4caac8856805b4d9463a87ab743c945da9e 100644 (file)
@@ -48,10 +48,18 @@ QString EncryptFolderJob::errorString() const
 void EncryptFolderJob::slotEncryptionFlagSuccess(const QByteArray &fileId)
 {
     SyncJournalFileRecord rec;
-    _journal->getFileRecord(_path, &rec);
-    if (rec.isValid()) {
-        rec._isE2eEncrypted = true;
-        _journal->setFileRecord(rec);
+    if (!_journal->getFileRecord(_path, &rec)) {
+        qCWarning(lcEncryptFolderJob) << "could not get file from local DB" << _path;
+    }
+
+    if (!rec.isValid()) {
+        qCWarning(lcEncryptFolderJob) << "No valid record found in local DB for fileId" << fileId;
+    }
+
+    rec._isE2eEncrypted = true;
+    const auto result = _journal->setFileRecord(rec);
+    if (!result) {
+        qCWarning(lcEncryptFolderJob) << "Error when setting the file record to the database" << rec._path << result.error();
     }
 
     auto lockJob = new LockEncryptFolderApiJob(_account, fileId, this);
index 0de8967dd7b81953ec847dbd068cf8892af12509..26c8a19e74233e15d179c9979e2b61a058ec5cb3 100644 (file)
@@ -289,7 +289,10 @@ void OCC::HydrationJob::finalize(OCC::VfsCfApi *vfs)
 {
     // Mark the file as hydrated in the sync journal
     SyncJournalFileRecord record;
-    _journal->getFileRecord(_folderPath, &record);
+    if (!_journal->getFileRecord(_folderPath, &record)) {
+        qCWarning(lcHydration) << "could not get file from local DB" << _folderPath;
+        return;
+    }
     Q_ASSERT(record.isValid());
     if (!record.isValid()) {
         qCWarning(lcHydration) << "Couldn't find record to update after hydration" << _requestId << _folderPath;
@@ -320,7 +323,10 @@ void OCC::HydrationJob::finalize(OCC::VfsCfApi *vfs)
     // store the actual size of a file that has been decrypted as we will need its actual size when dehydrating it if requested
     record._fileSize = FileSystem::getSize(localPath() + folderPath());
 
-    _journal->setFileRecord(record);
+    const auto result = _journal->setFileRecord(record);
+    if (!result) {
+        qCWarning(lcHydration) << "Error when setting the file record to the database" << record._path << result.error();
+    }
 }
 
 void OCC::HydrationJob::onGetFinished()
index 0ed2ce93b3ab2921502d93adab9268203fbb9137..21a7fd9505ec0f1dd8f9381213fccae2d6175a9d 100644 (file)
@@ -45,12 +45,17 @@ void VfsSuffix::startImpl(const VfsSetupParams &params)
     // that are not marked as a virtual file. These could be real .owncloud
     // files that were synced before vfs was enabled.
     QByteArrayList toWipe;
-    params.journal->getFilesBelowPath("", [&toWipe](const SyncJournalFileRecord &rec) {
+    if (!params.journal->getFilesBelowPath("", [&toWipe](const SyncJournalFileRecord &rec) {
         if (!rec.isVirtualFile() && rec._path.endsWith(APPLICATION_DOTVIRTUALFILE_SUFFIX))
             toWipe.append(rec._path);
-    });
-    for (const auto &path : toWipe)
-        params.journal->deleteFileRecord(path);
+    })) {
+        qWarning() << "Could not get files below path \"\" from local DB";
+    }
+    for (const auto &path : toWipe) {
+        if (!params.journal->deleteFileRecord(path)) {
+            qWarning() << "Failed to delete file record from local DB" << path;
+        }
+    }
 }
 
 void VfsSuffix::stop()