diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2021-06-28 13:32:57 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-06-28 19:16:58 +0300 |
commit | 1aa25a64a61f9058a66d94b98f8f188f7adca7af (patch) | |
tree | 2b178c606f997a1fc2108ce1f6b873e251a4b57e /src/common | |
parent | f5f06752e35ca3d6d2f316399aa119b1e57a51d1 (diff) |
Improve the error message returned by updateMetadata
Also properly handle the case the the file can't be converted to a placeholder
as it is locked
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/syncjournaldb.cpp | 11 | ||||
-rw-r--r-- | src/common/syncjournaldb.h | 2 | ||||
-rw-r--r-- | src/common/utility.cpp | 1 | ||||
-rw-r--r-- | src/common/vfs.h | 11 |
4 files changed, 16 insertions, 9 deletions
diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index dffdf44ae..0cfc0be3a 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -864,7 +864,7 @@ qint64 SyncJournalDb::getPHash(const QByteArray &file) return h; } -bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) +Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) { SyncJournalFileRecord record = _record; QMutexLocker locker(&_mutex); @@ -900,13 +900,12 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) QByteArray checksumType, checksum; parseChecksumHeader(record._checksumHeader, &checksumType, &checksum); int contentChecksumTypeId = mapChecksumType(checksumType); - const auto query = _queryManager.get(PreparedSqlQueryManager::SetFileRecordQuery, QByteArrayLiteral("INSERT OR REPLACE INTO metadata " "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentChecksum, contentChecksumTypeId) " "VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16);"), _db); if (!query) { - return false; + return query->error(); } query->bindValue(1, phash); @@ -927,16 +926,16 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) query->bindValue(16, contentChecksumTypeId); if (!query->exec()) { - return false; + return query->error(); } // Can't be true anymore. _metadataTableIsEmpty = false; - return true; + return {}; } else { qCWarning(lcDb) << "Failed to connect database."; - return false; // checkConnect failed. + return tr("Failed to connect database."); // checkConnect failed. } } diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h index 26e12c83c..0f8ff548a 100644 --- a/src/common/syncjournaldb.h +++ b/src/common/syncjournaldb.h @@ -64,7 +64,7 @@ public: bool getFileRecordsByFileId(const QByteArray &fileId, const std::function<void(const SyncJournalFileRecord &)> &rowCallback); bool getFilesBelowPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord&)> &rowCallback); bool listFilesInPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord&)> &rowCallback); - bool setFileRecord(const SyncJournalFileRecord &record); + Result<void, QString> setFileRecord(const SyncJournalFileRecord &record); bool deleteFileRecord(const QString &filename, bool recursively = false); bool updateFileRecordChecksum(const QString &filename, diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 08576c81e..e4336db60 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -637,4 +637,5 @@ QString Utility::sanitizeForFileName(const QString &name) } return result; } + } // namespace OCC diff --git a/src/common/vfs.h b/src/common/vfs.h index 678d2d39e..04a9f2003 100644 --- a/src/common/vfs.h +++ b/src/common/vfs.h @@ -97,6 +97,13 @@ public: WindowsCfApi, }; Q_ENUM(Mode) + enum class ConvertToPlaceholderResult { + Error, + Ok, + Locked + }; + Q_ENUM(ConvertToPlaceholderResult) + static QString modeToString(Mode mode); static Optional<Mode> modeFromString(const QString &str); @@ -187,7 +194,7 @@ public: * new placeholder shall supersede, for rename-replace actions with new downloads, * for example. */ - virtual OC_REQUIRED_RESULT Result<void, QString> convertToPlaceholder( + virtual OC_REQUIRED_RESULT Result<ConvertToPlaceholderResult, QString> convertToPlaceholder( const QString &filename, const SyncFileItem &item, const QString &replacesFile = QString()) = 0; @@ -293,7 +300,7 @@ public: Result<void, QString> updateMetadata(const QString &, time_t, qint64, const QByteArray &) override { return {}; } Result<void, QString> createPlaceholder(const SyncFileItem &) override { return {}; } Result<void, QString> dehydratePlaceholder(const SyncFileItem &) override { return {}; } - Result<void, QString> convertToPlaceholder(const QString &, const SyncFileItem &, const QString &) override { return {}; } + Result<ConvertToPlaceholderResult, QString> convertToPlaceholder(const QString &, const SyncFileItem &, const QString &) override { return ConvertToPlaceholderResult::Ok; } bool needsMetadataUpdate(const SyncFileItem &) override { return false; } bool isDehydratedPlaceholder(const QString &) override { return false; } |