From ecb78779084f0afd428a2f36e3d4efefc1e3c946 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 15 Mar 2017 18:05:06 +0100 Subject: [PATCH] refs #906, obtain .rev file name from static function instead of member --- src/blackmisc/datacache.cpp | 12 +++++++++--- src/blackmisc/datacache.h | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/blackmisc/datacache.cpp b/src/blackmisc/datacache.cpp index 02f36e71f..06f9f43e9 100644 --- a/src/blackmisc/datacache.cpp +++ b/src/blackmisc/datacache.cpp @@ -85,12 +85,12 @@ namespace BlackMisc connect(&m_watcher, &QFileSystemWatcher::fileChanged, this, &CDataCache::loadFromStoreAsync); connect(&m_serializer, &CDataCacheSerializer::valuesLoadedFromStore, this, &CDataCache::changeValuesFromRemote, Qt::DirectConnection); - if (! QFile::exists(m_revisionFileName)) { QFile(m_revisionFileName).open(QFile::WriteOnly); } + if (! QFile::exists(revisionFileName())) { QFile(revisionFileName()).open(QFile::WriteOnly); } m_serializer.loadFromStore({}, false, true); // load pinned values singleShot(0, this, [this] // only start the serializer if the main thread event loop runs { m_serializer.start(); - m_watcher.addPath(m_revisionFileName); + m_watcher.addPath(revisionFileName()); loadFromStoreAsync(); }); } @@ -107,6 +107,12 @@ namespace BlackMisc return dir; } + const QString &CDataCache::revisionFileName() + { + static const QString rev = CFileUtils::appendFilePaths(persistentStore(), ".rev"); + return rev; + } + QString CDataCache::filenameForKey(const QString &key) { return CFileUtils::appendFilePaths(persistentStore(), instance()->CValueCache::filenameForKey(key)); @@ -781,7 +787,7 @@ namespace BlackMisc QUuid uuid(json.value("uuid").toString()); CSequence apps; auto status = apps.convertFromJsonNoThrow(json.value("apps").toObject(), this, QStringLiteral("Error in %1 apps object").arg(m_filename)); - apps.removeIf([](const CProcessInfo &pi) { return ! pi.exists(); }); + apps.removeIf([](const CProcessInfo & pi) { return ! pi.exists(); }); if (apps.isEmpty()) { uuid = CIdentifier().toUuid(); } m_uuid = uuid; diff --git a/src/blackmisc/datacache.h b/src/blackmisc/datacache.h index 6053c7fb6..8c4fbdd66 100644 --- a/src/blackmisc/datacache.h +++ b/src/blackmisc/datacache.h @@ -255,6 +255,9 @@ namespace BlackMisc //! The directory where core data are stored. static const QString &persistentStore(); + //! Revision file name + static const QString &revisionFileName(); + //! Return the filename where the value with the given key may be stored. static QString filenameForKey(const QString &key); @@ -297,9 +300,8 @@ namespace BlackMisc virtual void connectPage(Private::CValuePage *page) override; QFileSystemWatcher m_watcher; - const QString m_revisionFileName { CFileUtils::appendFilePaths(persistentStore(), ".rev") }; - CDataCacheSerializer m_serializer { this, m_revisionFileName }; + CDataCacheSerializer m_serializer { this, revisionFileName() }; CDataCacheRevision m_revision { persistentStore() + "/" }; friend class CDataCacheSerializer; // to access m_revision and protected members of CValueCache };