ensure user receiving an encrypted share maintain proper state

will make sure the client internal database keeps proper encryption
information

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2025-03-13 11:36:10 +01:00
parent bf3ce29d1e
commit 1c90fb08e0
2 changed files with 9 additions and 1 deletions

View File

@ -72,6 +72,8 @@ void EncryptFolderJob::slotEncryptionFlagSuccess(const QByteArray &fileId)
if (!rec.isValid()) {
if (_propagator && _item) {
qCWarning(lcEncryptFolderJob) << "No valid record found in local DB for fileId" << fileId << "going to create it now...";
_item->_e2eEncryptionStatus = EncryptionStatusEnums::ItemEncryptionStatus::EncryptedMigratedV2_0;
_item->_e2eCertificateFingerprint = _account->e2e()->certificateSha256Fingerprint();
const auto updateResult = _propagator->updateMetadata(*_item.data());
if (updateResult) {
[[maybe_unused]] const auto result = _journal->getFileRecord(currentPath, &rec);
@ -81,7 +83,7 @@ void EncryptFolderJob::slotEncryptionFlagSuccess(const QByteArray &fileId)
}
}
if (!rec.isE2eEncrypted()) {
if (rec.isValid() && !rec.isE2eEncrypted()) {
rec._e2eEncryptionStatus = SyncJournalFileRecord::EncryptionStatus::Encrypted;
rec._e2eCertificateFingerprint = _account->e2e()->certificateSha256Fingerprint();
const auto result = _journal->setFileRecord(rec);

View File

@ -249,6 +249,8 @@ void PropagateUploadFileCommon::setupEncryptedFile(const QString& path, const QS
{
qCDebug(lcPropagateUpload) << "Starting to upload encrypted file" << path << filename << size;
_uploadingEncrypted = true;
_item->_e2eEncryptionStatus = EncryptionStatusEnums::ItemEncryptionStatus::EncryptedMigratedV2_0;
Q_ASSERT(_item->isEncrypted());
_fileToUpload._path = path;
_fileToUpload._file = filename;
_fileToUpload._size = size;
@ -450,6 +452,8 @@ void PropagateUploadFileCommon::slotFolderUnlocked(const QByteArray &folderId, i
void PropagateUploadFileCommon::slotOnErrorStartFolderUnlock(SyncFileItem::Status status, const QString &errorString)
{
if (_uploadingEncrypted) {
Q_ASSERT(_item->isEncrypted());
_uploadStatus = { status, errorString };
connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderUnlocked, this, &PropagateUploadFileCommon::slotFolderUnlocked);
_uploadEncryptedHelper->unlockFolder();
@ -839,6 +843,8 @@ void PropagateUploadFileCommon::finalize()
propagator()->_journal->commit("upload file start");
if (_uploadingEncrypted) {
Q_ASSERT(_item->isEncrypted());
_uploadStatus = { SyncFileItem::Success, QString() };
connect(_uploadEncryptedHelper, &PropagateUploadEncrypted::folderUnlocked, this, &PropagateUploadFileCommon::slotFolderUnlocked);
_uploadEncryptedHelper->unlockFolder();