From 70f9b2f953021d96f3c5de56fcc891920194dfa2 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 16 Aug 2023 13:27:47 +0300 Subject: [PATCH] kdecore: fix KSycoca dummy strategy setup the device was opened for reading only but for the version to be written it has to be opened for writing too Signed-off-by: Ivailo Monev --- kdecore/sycoca/ksycoca.cpp | 23 ++++------------------- kdecore/sycoca/ksycoca_p.h | 12 ++++++++++++ kdecore/sycoca/ksycocadevices_p.h | 6 ++++++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/kdecore/sycoca/ksycoca.cpp b/kdecore/sycoca/ksycoca.cpp index cb38accc..193c052e 100644 --- a/kdecore/sycoca/ksycoca.cpp +++ b/kdecore/sycoca/ksycoca.cpp @@ -44,19 +44,7 @@ #include "ksycocadevices_p.h" -/** - * Sycoca file version number. - * If the existing file is outdated, it will not get read - * but instead we'll ask kded to regenerate a new one... - */ -#define KSYCOCA_VERSION 244 - -/** - * Sycoca file name, used internally (by kbuildsycoca) - */ -#define KSYCOCA_FILENAME "ksycoca4" - -static bool s_autoRebuild = true; +static bool s_autoRebuild = false; // The following limitations are in place: // Maximum length of a single string: 8192 bytes @@ -165,9 +153,7 @@ bool KSycocaPrivate::openDatabase(bool openDummyIfNotFound) //kDebug(7011) << "No database, opening a dummy one."; m_sycocaStrategy = StrategyDummyBuffer; - QDataStream* str = stream(); - *str << qint32(KSYCOCA_VERSION); - *str << qint32(0); + (void)stream(); } else { result = false; } @@ -184,8 +170,7 @@ KSycocaAbstractDevice* KSycocaPrivate::device() KSycocaAbstractDevice* device = m_device; if (m_sycocaStrategy == StrategyDummyBuffer) { - device = new KSycocaBufferDevice; - device->device()->open(QIODevice::ReadOnly); // can't fail + device = new KSycocaBufferDevice(); } else { if (!device) { device = new KSycocaFileDevice(m_databasePath); @@ -303,7 +288,7 @@ bool KSycocaPrivate::checkVersion() QDataStream *m_str = device()->stream(); Q_ASSERT(m_str); m_str->device()->seek(0); - qint32 aVersion; + qint32 aVersion = 0; *m_str >> aVersion; if ( aVersion < KSYCOCA_VERSION ) { kWarning(7011) << "Found version" << aVersion << ", expecting version" << KSYCOCA_VERSION << "or higher."; diff --git a/kdecore/sycoca/ksycoca_p.h b/kdecore/sycoca/ksycoca_p.h index d8a46592..925d6c3b 100644 --- a/kdecore/sycoca/ksycoca_p.h +++ b/kdecore/sycoca/ksycoca_p.h @@ -26,6 +26,18 @@ #include #include +/** + * Sycoca file version number. + * If the existing file is outdated, it will not get read + * but instead we'll ask kded to regenerate a new one... + */ +#define KSYCOCA_VERSION 244 + +/** + * Sycoca file name, used internally (by kbuildsycoca) + */ +#define KSYCOCA_FILENAME "ksycoca4" + class KSycocaAbstractDevice; class KSycocaPrivate diff --git a/kdecore/sycoca/ksycocadevices_p.h b/kdecore/sycoca/ksycocadevices_p.h index 4a178f2a..e113bec8 100644 --- a/kdecore/sycoca/ksycocadevices_p.h +++ b/kdecore/sycoca/ksycocadevices_p.h @@ -22,6 +22,8 @@ #ifndef KSYCOCADEVICES_P_H #define KSYCOCADEVICES_P_H +#include "ksycoca_p.h" + class KSycocaAbstractDevice { public: @@ -67,6 +69,10 @@ class KSycocaBufferDevice : public KSycocaAbstractDevice public: KSycocaBufferDevice() { m_buffer = new QBuffer(); + m_buffer->open(QIODevice::ReadWrite); // can't fail + QDataStream str(m_buffer); + str << qint32(KSYCOCA_VERSION); + str << qint32(0); } ~KSycocaBufferDevice() { delete m_buffer;