From: Felix Weilbach Date: Tue, 16 Nov 2021 10:50:43 +0000 (+0100) Subject: Correct virtual files placeholder files if needed X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~18^2~106^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c76a77e43101e7825c79f8e1412609eb66ebfde0;p=nextcloud-desktop.git Correct virtual files placeholder files if needed In the past not all files were converted to placeholder files when converting an existing sync folder to a virtual files folder. Because some files were not converted to placeholder files, the status would be wrong on the files. This code makes sure that every file in a virtual files folder is a placeholder file. It could be removed in the future. Signed-off-by: Felix Weilbach --- diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index 5c5195bba..8c41aec63 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -1016,6 +1016,29 @@ qint64 SyncJournalDb::keyValueStoreGetInt(const QString &key, qint64 defaultValu return query->int64Value(0); } +bool SyncJournalDb::keyValueStoreGetBool(const QString &key, bool defaultValue) +{ + QMutexLocker locker(&_mutex); + if (!checkConnect()) { + return defaultValue; + } + + const auto query = _queryManager.get(PreparedSqlQueryManager::GetKeyValueStoreQuery, + QByteArrayLiteral("SELECT value FROM key_value_store WHERE key = ?1;"), _db); + if (!query) { + return defaultValue; + } + + query->bindValue(1, key); + query->exec(); + + if (!query->next().hasData) { + return defaultValue; + } + + return query->intValue(0); +} + QVariant SyncJournalDb::keyValueStoreGet(const QString &key, QVariant defaultValue) { QMutexLocker locker(&_mutex); diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h index ba4c0ede8..9a3db7125 100644 --- a/src/common/syncjournaldb.h +++ b/src/common/syncjournaldb.h @@ -70,6 +70,7 @@ public: void keyValueStoreSet(const QString &key, QVariant value); qint64 keyValueStoreGetInt(const QString &key, qint64 defaultValue); + bool keyValueStoreGetBool(const QString &key, bool defaultValue); QVariant keyValueStoreGet(const QString &key, QVariant defaultValue = {}); void keyValueStoreDelete(const QString &key); diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index decbb927b..39e4d37a9 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -866,11 +866,27 @@ void Folder::startSync(const QStringList &pathList) _engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles); + correctPlaceholderFiles(); + QMetaObject::invokeMethod(_engine.data(), "startSync", Qt::QueuedConnection); emit syncStarted(); } +void Folder::correctPlaceholderFiles() +{ + if (_definition.virtualFilesMode == Vfs::Off) { + return; + } + static const auto placeholdersCorrectedKey = QStringLiteral("placeholders_corrected"); + const auto placeholdersCorrected = _journal.keyValueStoreGetBool(placeholdersCorrectedKey, false); + if (!placeholdersCorrected) { + qCDebug(lcFolder) << "Make sure all virtual files are placeholder files"; + switchToVirtualFiles(); + _journal.keyValueStoreSet(placeholdersCorrectedKey, true); + } +} + void Folder::setSyncOptions() { SyncOptions opt; diff --git a/src/gui/folder.h b/src/gui/folder.h index 3bb96b2da..8fd8bfbbb 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -444,6 +444,8 @@ private: void startVfs(); + void correctPlaceholderFiles(); + AccountStatePtr _accountState; FolderDefinition _definition; QString _canonicalLocalPath; // As returned with QFileInfo:canonicalFilePath. Always ends with "/"