generic: run kbuildsycoca4 directly when checking database and start kded4 only to monitor resources

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-05-26 12:18:56 +03:00
parent 3596ccd22e
commit 84afe0c4a9
4 changed files with 37 additions and 131 deletions

View file

@ -342,16 +342,10 @@ bool KSycocaPrivate::checkDatabase(BehaviorsIfNotFound ifNotFound)
}
if (ifNotFound & IfNotFoundRecreate) {
// Well, if kded is not running we need to launch it,
// but otherwise we simply need to run kbuildsycoca to recreate the sycoca file.
if (!kdedRunning) {
kDebug(7011) << "We have no database.... launching kded";
sessionInterface->startService(kdedInterface);
} else {
kDebug(7011) << QThread::currentThread() << "We have no database.... launching" << KBUILDSYCOCA_EXENAME;
if (QProcess::execute(KStandardDirs::findExe(QString::fromLatin1(KBUILDSYCOCA_EXENAME))) != 0) {
qWarning("ERROR: Running KSycoca failed.");
}
// We simply need to run kbuildsycoca to recreate the sycoca file.
kDebug(7011) << QThread::currentThread() << "We have no database.... launching" << KBUILDSYCOCA_EXENAME;
if (QProcess::execute(KStandardDirs::findExe(QString::fromLatin1(KBUILDSYCOCA_EXENAME))) != 0) {
kWarning(7011) << "Running KSycoca failed.";
}
closeDatabase(); // close the dummy one
@ -365,6 +359,13 @@ bool KSycocaPrivate::checkDatabase(BehaviorsIfNotFound ifNotFound)
kDebug(7011) << "Still outdated...";
return false; // Still outdated - uh oh
}
// If kded is not running we need to launch it as it monitors for changes
if (!kdedRunning) {
kDebug(7011) << "Launching kded";
sessionInterface->startService(kdedInterface);
}
return true;
}
@ -469,15 +470,16 @@ QStringList KSycoca::allResourceDirs()
void KSycoca::flagError()
{
kWarning(7011) << "ERROR: KSycoca database corruption!";
kWarning(7011) << "KSycoca database corruption!";
KSycocaPrivate* d = ksycocaInstance->sycoca()->d;
if (d->readError)
return;
d->readError = true;
if (s_autoRebuild) {
// Rebuild the damned thing.
if (QProcess::execute(KStandardDirs::findExe(QString::fromLatin1(KBUILDSYCOCA_EXENAME))) != 0)
qWarning("ERROR: Running %s failed", KBUILDSYCOCA_EXENAME);
if (QProcess::execute(KStandardDirs::findExe(QString::fromLatin1(KBUILDSYCOCA_EXENAME))) != 0) {
kWarning(7011) << "Running KSycoca failed.";
}
// Old comment, maybe not true anymore:
// Do not wait until the DBUS signal from kbuildsycoca here.
// It deletes m_str which is a problem when flagError is called during the KSycocaFactory ctor...

View file

@ -11,11 +11,6 @@ software is detected. Updating of ksycoca is done by the program kbuildsycoca
which gets started by kded. When kded is first started it always runs
kbuildsycoca to ensure that ksycoca is up to date.
*) Checking for newly installed update files. Applications can install
*.upd update files. These *.upd files are used to update configuration files
of users, primarily when new versions of applications are installed with
(slightly) different configuration file formats.
*) Checking for hostname changes. It is a really bad idea to change the
hostname of a running system and it usually only happens with incorrectly
configured dial-up connections. Never the less, kded will check for hostname
@ -50,35 +45,18 @@ Example kdedrc file with default values:
[General]
HostnamePollInterval=5000
CheckSycoca=true
CheckUpdates=true
CheckHostname=true
CheckFileStamps=true
DelayedCheck=false
If FAM or DNOTIFY is not available, the filesystem will be polled at regular interval for any changes. Under the [DirWatch] group in the kdeglobals file
the following options are available to adjust the polling frequency:
The filesystem will be polled at regular interval for any changes. Under the
[DirWatch] group in the kdeglobals file the following options are available
to adjust the polling frequency:
PollInterval: This can be used to adjust the time interval at which the local
filesystem is checked for new software or update files. The time is specified
in milliseconds and has a default of 500 (0.5 seconds).
NFSPollInterval: This can be used to adjust the time interval at which remote
filesystems, such as NFS or Samba, are ebing checked for new software or
update files. The time is specified in milliseconds and has a default of 5000
(5 seconds).
The above options are not used when FAM is used to watch for changes in the
filesystem, or when DNOTIFY is used. Specifying larger intervals may reduce
the CPU load and/or network traffic. Shorter intervals are not recommended.
Please note that in previous versions of KDE these options where listed in
the kderc file.
Example kdeglobals fragment:
[DirWatch]
PollInterval=500
NFSPollInterval=5000
in milliseconds and has a default of 5000 (5 seconds). Specifying larger
intervals may reduce the CPU load and/or network traffic. Shorter intervals
are not recommended.
KDED modules
============

View file

@ -56,11 +56,9 @@
Kded *Kded::_self = 0;
static bool checkStamps = true;
static bool delayedCheck = false;
static int HostnamePollInterval = 5000;
static bool bCheckStamps = true;
static bool bCheckSycoca = true;
static bool bCheckUpdates = true;
static bool bCheckHostname = true;
QT_BEGIN_NAMESPACE
@ -72,14 +70,9 @@ static bool runBuildSycoca()
const QString exe = KStandardDirs::findExe(KBUILDSYCOCA_EXENAME);
Q_ASSERT(!exe.isEmpty());
QStringList args;
if (checkStamps) {
if (bCheckStamps) {
args.append("--checkstamps");
}
if (delayedCheck) {
args.append("--nocheckfiles");
} else {
checkStamps = false; // useful only during kded startup
}
return (QProcess::execute(exe, args) == 0);
}
@ -96,14 +89,10 @@ Kded::Kded(QObject *parent)
m_pDirWatch(nullptr),
m_pTimer(nullptr),
m_recreateBusy(false),
m_serviceWatcher(nullptr),
m_needDelayedCheck(false)
m_serviceWatcher(nullptr)
{
_self = this;
m_pDirWatch = new KDirWatch(this);
connect(m_pDirWatch, SIGNAL(dirty(QString)), this, SLOT(update(QString)));
m_serviceWatcher = new QDBusServiceWatcher(this);
m_serviceWatcher->setConnection(QDBusConnection::sessionBus());
m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
@ -118,6 +107,10 @@ Kded::Kded(QObject *parent)
session.registerObject("/kded", this);
session.registerService("org.kde.kded");
updateDirWatch();
updateResourceList();
initModules();
qDBusAddSpyHook(messageFilter);
m_pTimer = new QTimer(this);
@ -433,7 +426,7 @@ void Kded::slotApplicationRemoved(const QString &name)
void Kded::updateDirWatch()
{
if (!bCheckUpdates) {
if (!bCheckSycoca) {
return;
}
@ -450,10 +443,6 @@ void Kded::updateResourceList()
{
KSycoca::clearCaches();
if (!bCheckUpdates || delayedCheck) {
return;
}
foreach(const QString &it, KSycoca::self()->allResourceDirs()) {
if (!m_allResourceDirs.contains(it)) {
m_allResourceDirs.append(it);
@ -463,63 +452,11 @@ void Kded::updateResourceList()
}
void Kded::recreate()
{
recreate(false);
}
void Kded::runDelayedCheck()
{
if (m_needDelayedCheck) {
recreate(false);
}
m_needDelayedCheck = false;
}
void Kded::recreate(bool initial)
{
m_recreateBusy = true;
// Using KLauncher here is difficult since we might not have a
// database
if (initial) {
updateDirWatch(); // Update tree first, to be sure to miss nothing.
if (runBuildSycoca()) {
recreateDone();
} else {
recreateFailed();
}
} else {
if (!delayedCheck) {
updateDirWatch(); // this would search all the directories
}
if (bCheckSycoca) {
runBuildSycoca();
}
recreateDone();
if (delayedCheck) {
// do a proper ksycoca check after a delay
QTimer::singleShot(60000, this, SLOT(runDelayedCheck()));
m_needDelayedCheck = true;
delayedCheck = false;
} else {
m_needDelayedCheck = false;
}
}
}
void Kded::recreateFailed()
{
afterRecreateFinished();
}
void Kded::recreateDone()
{
updateDirWatch(); // this would search all the directories
runBuildSycoca();
updateResourceList();
afterRecreateFinished();
}
void Kded::afterRecreateFinished()
{
m_recreateBusy = false;
initModules();
@ -534,6 +471,10 @@ void Kded::update(const QString& )
void Kded::readDirectory(const QString& _path)
{
if (!bCheckSycoca) {
return;
}
QString path(_path);
if (!path.endsWith('/')) {
path += '/';
@ -544,7 +485,7 @@ void Kded::readDirectory(const QString& _path)
return;
}
m_pDirWatch->addDir(path,KDirWatch::WatchFiles|KDirWatch::WatchSubDirs);
m_pDirWatch->addDir(path, KDirWatch::WatchFiles|KDirWatch::WatchSubDirs);
}
#if 0
@ -665,13 +606,10 @@ int main(int argc, char *argv[])
KConfigGroup cg(config, "General");
HostnamePollInterval = cg.readEntry("HostnamePollInterval", 5000);
bCheckSycoca = cg.readEntry("CheckSycoca", true);
bCheckUpdates = cg.readEntry("CheckUpdates", true);
bCheckHostname = cg.readEntry("CheckHostname", true);
checkStamps = cg.readEntry("CheckFileStamps", true);
delayedCheck = cg.readEntry("DelayedCheck", false);
bCheckStamps = cg.readEntry("CheckFileStamps", true);
Kded kded(&app);
kded.recreate(true); // Build initial database
#ifdef Q_WS_X11
XEvent e;

View file

@ -68,7 +68,6 @@ public:
*/
void unregisterWindowId(qlonglong windowId, const QString &sender);
//@}
void recreate(bool initial);
void loadSecondPhase();
//@{
@ -132,12 +131,6 @@ public Q_SLOTS:
*/
void recreate();
/**
* Recreating finished
*/
void recreateDone();
void recreateFailed();
/**
* Collect all directories to watch
*/
@ -165,11 +158,7 @@ protected Q_SLOTS:
*/
void update(const QString& dir);
void runDelayedCheck();
private:
void afterRecreateFinished();
/**
* Scans dir for new files and new subdirectories.
*/
@ -201,7 +190,6 @@ private:
QSet<long> m_globalWindowIdList;
QStringList m_allResourceDirs;
bool m_needDelayedCheck;
static Kded *_self;
};