Do not ignore return values for SyncJournalDB calls in propagator jobs and discovery.

Signed-off-by: allexzander <blackslayer4@gmail.com>
This commit is contained in:
allexzander 2022-08-04 16:47:39 +03:00 committed by Matthieu Gallien
parent 1694be9d72
commit d7950304ee
4 changed files with 49 additions and 10 deletions

View File

@ -914,7 +914,10 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
} else if (noServerEntry) {
// Not locally, not on the server. The entry is stale!
qCInfo(lcDisco) << "Stale DB entry";
_discoveryData->_statedb->deleteFileRecord(path._original, true);
if (!_discoveryData->_statedb->deleteFileRecord(path._original, true)) {
_discoveryData->fatalError(tr("Error while deleting file record %1 from the database").arg(path._original));
qCWarning(lcDisco) << "Failed to delete a file record from the local DB" << path._original;
}
return;
} else if (dbEntry._type == ItemTypeVirtualFile && isVfsWithSuffix()) {
// If the virtual file is removed, recreate it.
@ -1270,7 +1273,9 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
if (wasDeletedOnClient.first) {
// More complicated. The REMOVE is canceled. Restore will happen next sync.
qCInfo(lcDisco) << "Undid remove instruction on source" << originalPath;
_discoveryData->_statedb->deleteFileRecord(originalPath, true);
if (!_discoveryData->_statedb->deleteFileRecord(originalPath, true)) {
qCWarning(lcDisco) << "Failed to delete a file record from the local DB" << originalPath;
}
_discoveryData->_statedb->schedulePathForRemoteDiscovery(originalPath);
_discoveryData->_anotherSyncNeeded = true;
} else {
@ -1423,7 +1428,10 @@ void ProcessDirectoryJob::processFileConflict(const SyncFileItemPtr &item, Proce
rec._fileSize = serverEntry.size;
rec._remotePerm = serverEntry.remotePerm;
rec._checksumHeader = serverEntry.checksumHeader;
_discoveryData->_statedb->setFileRecord(rec);
const auto result = _discoveryData->_statedb->setFileRecord(rec);
if (!result) {
qCWarning(lcDisco) << "Error when setting the file record to the database" << result.error();
}
}
return;
}

View File

@ -319,7 +319,11 @@ bool PropagateItemJob::hasEncryptedAncestor() const
auto pathComponents = parentPath.split('/');
while (!pathComponents.isEmpty()) {
SyncJournalFileRecord rec;
propagator()->_journal->getFileRecord(pathComponents.join('/'), &rec);
const auto pathCompontentsJointed = pathComponents.join('/');
if (!propagator()->_journal->getFileRecord(pathCompontentsJointed, &rec)) {
qCWarning(lcPropagator) << "could not get file from local DB" << pathCompontentsJointed;
}
if (rec.isValid() && rec._isE2eEncrypted) {
return true;
}
@ -1194,7 +1198,11 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
// that may still exist below the old path.
if (_item->_instruction == CSYNC_INSTRUCTION_RENAME
&& _item->_originalFile != _item->_renameTarget) {
propagator()->_journal->deleteFileRecord(_item->_originalFile, true);
if (!propagator()->_journal->deleteFileRecord(_item->_originalFile, true)) {
qCWarning(lcDirectory) << "could not delete file from local DB" << _item->_originalFile;
return;
}
}
if (_item->_instruction == CSYNC_INSTRUCTION_NEW && _item->_direction == SyncFileItem::Down) {

View File

@ -459,7 +459,11 @@ void PropagateDownloadFile::start()
const auto parentPath = slashPosition >= 0 ? path.left(slashPosition) : QString();
SyncJournalFileRecord parentRec;
propagator()->_journal->getFileRecord(parentPath, &parentRec);
if (!propagator()->_journal->getFileRecord(parentPath, &parentRec)) {
qCWarning(lcPropagateDownload) << "could not get file from local DB" << parentPath;
done(SyncFileItem::NormalError, tr("could not get file %1 from local DB").arg(parentPath));
return;
}
const auto account = propagator()->account();
if (!account->capabilities().clientSideEncryptionAvailable() ||
@ -502,7 +506,13 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked()
done(SyncFileItem::NormalError, r.error());
return;
}
propagator()->_journal->deleteFileRecord(_item->_originalFile);
if (!propagator()->_journal->deleteFileRecord(_item->_originalFile)) {
qCWarning(lcPropagateDownload) << "could not delete file from local DB" << _item->_originalFile;
done(SyncFileItem::NormalError, tr("could not delete file %1 from local DB").arg(_item->_originalFile));
return;
}
updateMetadata(false);
if (!_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite)) {
@ -1236,7 +1246,12 @@ void PropagateDownloadFile::downloadFinished()
auto fn = propagator()->fullLocalPath(virtualFile);
qCDebug(lcPropagateDownload) << "Download of previous virtual file finished" << fn;
QFile::remove(fn);
propagator()->_journal->deleteFileRecord(virtualFile);
if (!propagator()->_journal->deleteFileRecord(virtualFile)) {
qCWarning(lcPropagateDownload) << "could not delete file from local DB" << virtualFile;
done(SyncFileItem::NormalError, tr("could not delete file %1 from local DB").arg(virtualFile));
return;
}
// Move the pin state to the new location
auto pin = propagator()->_journal->internalPinStates().rawForPath(virtualFile.toUtf8());

View File

@ -245,7 +245,11 @@ void PropagateRemoteMove::finalize()
// The db is only queried to transfer the content checksum from the old
// to the new record. It is not a problem to skip it here.
SyncJournalFileRecord oldRecord;
propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord);
if (!propagator()->_journal->getFileRecord(_item->_originalFile, &oldRecord)) {
qCWarning(lcPropagateRemoteMove) << "could not get file from local DB" << _item->_originalFile;
done(SyncFileItem::NormalError, tr("could not get file %1 from local DB").arg(_item->_originalFile));
return;
}
auto &vfs = propagator()->syncOptions()._vfs;
auto pinState = vfs->pinState(_item->_originalFile);
@ -253,7 +257,11 @@ void PropagateRemoteMove::finalize()
if (QFileInfo::exists(targetFile)) {
// Delete old db data.
propagator()->_journal->deleteFileRecord(_item->_originalFile);
if (!propagator()->_journal->deleteFileRecord(_item->_originalFile)) {
qCWarning(lcPropagateRemoteMove) << "could not delete file from local DB" << _item->_originalFile;
done(SyncFileItem::NormalError, tr("could not delete file %1 from local DB").arg(_item->_originalFile));
return;
}
if (!vfs->setPinState(_item->_originalFile, PinState::Inherited)) {
qCWarning(lcPropagateRemoteMove) << "Could not set pin state of" << _item->_originalFile << "to inherited";
}