Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ debian/deepin-anything-server.debhelper.log
src/kernelmod/.Module.symvers.cmd
src/kernelmod/.modules.order.cmd
src/kernelmod/.vfs_monitor.mod.cmd
.pms/
47 changes: 30 additions & 17 deletions assets/org.deepin.anything.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,92 @@
"version": "1.0",
"contents": {
"indexing_paths": {
"value": ["$HOME"],
"value": [
"$HOME"
],
"serial": 0,
"flags":[],
"flags": [],
"name": "Indexing Paths",
"name[zh_CN]": "索引路径",
"description": "Indexing Paths",
"description[zh_CN]":"索引路径",
"description[zh_CN]": "索引路径",
"permissions": "readwrite",
"visibility": "public"
},
"blacklist_paths": {
"value": [],
"serial": 0,
"flags":[],
"flags": [],
"name": "Blacklist Paths",
"name[zh_CN]": "黑名单路径",
"description": "Blacklist Paths",
"description[zh_CN]":"黑名单路径",
"description[zh_CN]": "黑名单路径",
"permissions": "readwrite",
"visibility": "public"
},
"app_file_suffix": {
"value": "desktop",
"serial": 0,
"flags":[],
"flags": [],
"name": "App File Suffix",
"name[zh_CN]": "应用文件后缀",
"description": "App File Suffix",
"description[zh_CN]":"应用文件后缀",
"description[zh_CN]": "应用文件后缀",
"permissions": "readwrite",
"visibility": "public"
},
"archive_file_suffix": {
"value": "7z;ace;arj;bz2;cab;gz;gzip;jar;r00;r01;r02;r03;r04;r05;r06;r07;r08;r09;r10;r11;r12;r13;r14;r15;r16;r17;r18;r19;r20;r21;r22;r23;r24;r25;r26;r27;r28;r29;rar;tar;tgz;z;zip",
"serial": 0,
"flags":[],
"flags": [],
"name": "Archive File Suffix",
"name[zh_CN]": "归档文件后缀",
"description": "Archive File Suffix",
"description[zh_CN]":"归档文件后缀",
"description[zh_CN]": "归档文件后缀",
"permissions": "readwrite",
"visibility": "public"
},
"audio_file_suffix": {
"value": "aac;ac3;aif;aifc;aiff;au;cda;dts;fla;flac;it;m1a;m2a;m3u;m4a;mid;midi;mka;mod;mp2;mp3;mpa;ogg;opus;ra;rmi;spc;rmi;snd;umx;voc;wav;wma;xm;ape",
"serial": 0,
"flags":[],
"flags": [],
"name": "Audio File Suffix",
"name[zh_CN]": "音频文件后缀",
"description": "Audio File Suffix",
"description[zh_CN]":"音频文件后缀",
"description[zh_CN]": "音频文件后缀",
"permissions": "readwrite",
"visibility": "public"
},
"doc_file_suffix": {
"value": "c;chm;cpp;csv;cxx;doc;docm;docx;dot;dotm;dotx;h;hpp;htm;html;hxx;ini;java;lua;mht;mhtml;ods;odt;odp;pdf;potx;potm;ppam;ppsm;ppsx;pps;ppt;pptm;pptx;rtf;sldm;sldx;thmx;txt;vsd;wpd;wps;wri;xlam;xls;xlsb;xlsm;xlsx;xltm;xltx;xml;latex;wpt;md;odg;dps;sh;xhtml;dhtml;shtm;shtml;json;css;yaml;bat;js;sql;uof;ofd;log;tex",
"serial": 0,
"flags":[],
"flags": [],
"name": "Doc File Suffix",
"name[zh_CN]": "文档文件后缀",
"description": "Doc File Suffix",
"description[zh_CN]":"文档文件后缀",
"description[zh_CN]": "文档文件后缀",
"permissions": "readwrite",
"visibility": "public"
},
"pic_file_suffix": {
"value": "ani;avif;avifs;bmp;bw;dci;eps;epsf;epsi;exr;gif;heic;heif;heis;heix;icns;ico;jpe;jpeg;jpg;kra;mng;ora;pcx;pic;png;psd;raf;ras;raw;rgb;rgba;sgi;svg;svgz;tga;tif;tiff;wbmp;webp;wmf;xcf;cr2;crw;nef;dng;arw;orf;rw2;pef;srw;mrw;x3f;dcr;kdc;3fr;nrw;mef;iiq;sr2;erf;mos;rwl",
"serial": 0,
"flags":[],
"flags": [],
"name": "Pic File Suffix",
"name[zh_CN]": "图片文件后缀",
"description": "Pic File Suffix",
"description[zh_CN]":"图片文件后缀",
"description[zh_CN]": "图片文件后缀",
"permissions": "readwrite",
"visibility": "public"
},
"video_file_suffix": {
"value": "3g2;3gp;3gp2;3gpp;amr;amv;asf;asx;avi;bdmv;bik;d2v;divx;drc;dsa;dsm;dss;dsv;evo;f4v;flc;fli;flic;flv;hdmov;ifo;ivf;m1v;m2p;m2t;m2ts;m2v;m4b;m4p;m4v;mkv;mp2v;mp4;mp4v;mpe;mpeg;mpg;mpls;mpv2;mpv4;mov;mts;ogm;ogv;pss;pva;qt;ram;ratdvd;rm;rmm;rmvb;roq;rpm;smil;smk;swf;tp;tpr;ts;vob;vp6;webm;wm;wmp;wmv",
"serial": 0,
"flags":[],
"flags": [],
"name": "Video File Suffix",
"name[zh_CN]": "视频文件后缀",
"description": "Video File Suffix",
"description[zh_CN]":"视频文件后缀",
"description[zh_CN]": "视频文件后缀",
"permissions": "readwrite",
"visibility": "public"
},
Expand Down Expand Up @@ -133,6 +135,17 @@
"description[zh_CN]": "触发 updating 的事件数",
"permissions": "readwrite",
"visibility": "public"
},
"idle_exit_timeout_minutes": {
"value": 10,
"serial": 0,
"flags": [],
"name": "Idle Exit Timeout Minutes",
"name[zh_CN]": "空闲退出超时时间(分钟)",
"description": "Minutes of D-Bus inactivity before the index service auto-exits (0 = never exit)",
"description[zh_CN]": "索引服务空闲多少分钟后自动退出(0 = 永不退出)",
"permissions": "readwrite",
"visibility": "public"
}
}
}
1 change: 1 addition & 0 deletions src/index/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ set(INDEX_SOURCES
dbus/ocrindexdbus.cpp
dbus/filenameindexdbus.cpp
serviceentry.cpp
idleexitmanager.cpp
)
list(TRANSFORM INDEX_SOURCES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/)
file(GLOB_RECURSE INDEX_HEADERS CONFIGURE_DEPENDS "*.h")
Expand Down
84 changes: 84 additions & 0 deletions src/index/idleexitmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "idleexitmanager.h"
#include "serviceentry.h"

#include <QCoreApplication>

Check warning on line 8 in src/index/idleexitmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 9 in src/index/idleexitmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusMessage>

Check warning on line 10 in src/index/idleexitmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusMessage> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 11 in src/index/idleexitmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DConfig>

Check warning on line 12 in src/index/idleexitmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// qDBusAddSpyHook is a Qt DBus internal function exported from libQt6DBus.
// It registers a callback invoked for every D-Bus message that flows
// through the connection (both incoming and outgoing). The callback
// runs on the main thread, so touching the QTimer directly is safe.
//
// The symbol is not declared in any public Qt6 header, so we declare
// it here. It is a C++ function (not extern "C"), so the linker must
// resolve the mangled symbol _Z15qDBusAddSpyHookPFvRK12QDBusMessageE
// that libQt6DBus exports. Using extern "C" would search for the
// unmangled name and fail at link time.
Q_DECL_IMPORT void qDBusAddSpyHook(void (*)(const QDBusMessage &));

namespace anything_index {

static constexpr char kAnythingAppId[] = "org.deepin.anything";
static constexpr char kAnythingSchema[] = "org.deepin.anything";
static constexpr char kIdleExitTimeoutKey[] = "idle_exit_timeout_minutes";
static constexpr int kDefaultIdleExitTimeoutMinutes = 10;

static QTimer *g_idleTimer = nullptr;

static void idleSpyHook(const QDBusMessage &)
{
if (g_idleTimer)
g_idleTimer->start();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Activity from worker threads is missed

When a D-Bus message is sent from a thread other than the one that owns g_idleTimer, idleSpyHook calls QTimer::start() directly even though the hook runs synchronously for D-Bus messages and can be invoked by a thread sending a message; starting a main-thread timer from that thread is unsafe and does not reliably reset the timeout, so the service can exit despite D-Bus activity.

Marshal the timer reset to the timer's owning thread, for example by queuing a slot or invocation on the timer.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at line 38:

**Activity from worker threads is missed**

When a D-Bus message is sent from a thread other than the one that owns `g_idleTimer`, `idleSpyHook` calls `QTimer::start()` directly even though the hook runs synchronously for D-Bus messages and can be invoked by a thread sending a message; starting a main-thread timer from that thread is unsafe and does not reliably reset the timeout, so the service can exit despite D-Bus activity.

Marshal the timer reset to the timer's owning thread, for example by queuing a slot or invocation on the timer.

}

void startIdleExitManager()
{
int timeoutMinutes = kDefaultIdleExitTimeoutMinutes;

const std::unique_ptr<Dtk::Core::DConfig> dconfig(
Dtk::Core::DConfig::create(QString::fromLatin1(kAnythingAppId),
QString::fromLatin1(kAnythingSchema)));
if (dconfig && dconfig->isValid()) {
timeoutMinutes = dconfig->value(QString::fromLatin1(kIdleExitTimeoutKey),
kDefaultIdleExitTimeoutMinutes).toInt();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Malformed setting disables auto-exit

When the dconfig value is present but cannot be converted to an integer, a non-numeric configured value makes toInt() return 0, which the following check treats as the explicit “disable auto-exit” setting. The service then stays running indefinitely instead of using the default timeout, with no warning about the invalid value.

Check conversion success and use the default timeout with a warning when the value is invalid.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at line 50:

**Malformed setting disables auto-exit**

When the dconfig value is present but cannot be converted to an integer, a non-numeric configured value makes `toInt()` return 0, which the following check treats as the explicit “disable auto-exit” setting. The service then stays running indefinitely instead of using the default timeout, with no warning about the invalid value.

Check conversion success and use the default timeout with a warning when the value is invalid.

if (timeoutMinutes < 0) {
qWarning() << "deepin-anything-index: invalid idle_exit_timeout_minutes"
<< timeoutMinutes << ", using default"
<< kDefaultIdleExitTimeoutMinutes;
timeoutMinutes = kDefaultIdleExitTimeoutMinutes;
}
} else {
qWarning() << "deepin-anything-index: failed to load dconfig for idle exit"
"timeout, using default" << kDefaultIdleExitTimeoutMinutes
<< "minutes";
}

if (timeoutMinutes == 0) {
qInfo() << "deepin-anything-index: idle exit disabled (timeout = 0)";
return;
}

g_idleTimer = new QTimer;
g_idleTimer->setSingleShot(true);
g_idleTimer->setInterval(timeoutMinutes * 60 * 1000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Configured idle timeout is not honored

When idle_exit_timeout_minutes is configured above 35,791, the signed timeoutMinutes * 60 * 1000 calculation overflows before QTimer::setInterval() receives it, so the timer uses an unintended interval and the service exits at the wrong time or fails to time out as configured.

Calculate the interval without signed-integer overflow and handle values outside the timer's supported range.

Also at src/index/idleexitmanager.cpp:71.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at line 70:

**Configured idle timeout is not honored**

When `idle_exit_timeout_minutes` is configured above 35,791, the signed `timeoutMinutes * 60 * 1000` calculation overflows before `QTimer::setInterval()` receives it, so the timer uses an unintended interval and the service exits at the wrong time or fails to time out as configured.

Calculate the interval without signed-integer overflow and handle values outside the timer's supported range.

Also at `src/index/idleexitmanager.cpp:71`.


QObject::connect(g_idleTimer, &QTimer::timeout, []() {
qInfo() << "deepin-anything-index: idle timeout reached,"
"exiting to release resources (D-Bus activation will"
"restart on next request)";
unregisterIndexServices();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Active indexing work is interrupted

When an indexing task runs longer than the configured timeout without D-Bus activity, unregisterIndexServices() runs cleanup, which stops the task and marks unfinished work dirty, so indexing is aborted and needs recovery on the next startup.

Defer the idle exit while indexing work is active.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at line 76:

**Active indexing work is interrupted**

When an indexing task runs longer than the configured timeout without D-Bus activity, `unregisterIndexServices()` runs cleanup, which stops the task and marks unfinished work dirty, so indexing is aborted and needs recovery on the next startup.

Defer the idle exit while indexing work is active.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · OCR and filename requests fail after exit

When the process has exited and the next request targets only the OCR or filename service, the installed D-Bus activation entry names only TextIndex, so a request to the OCR or filename service cannot activate the process and fails with a missing-service error.

Add D-Bus activation entries for the OCR and filename service names, or otherwise ensure requests to those names activate the process.

Also at src/index/idleexitmanager.cpp:77, src/index/idleexitmanager.h:20, src/index/main.cpp:139.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at line 76:

**OCR and filename requests fail after exit**

When the process has exited and the next request targets only the OCR or filename service, the installed D-Bus activation entry names only TextIndex, so a request to the OCR or filename service cannot activate the process and fails with a missing-service error.

Add D-Bus activation entries for the OCR and filename service names, or otherwise ensure requests to those names activate the process.

Also at `src/index/idleexitmanager.cpp:77`, `src/index/idleexitmanager.h:20`, `src/index/main.cpp:139`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Idle shutdown appears as backend failure

When the idle timer expires while dde-file-manager is watching the index service, the service unregisters its names on a normal idle exit, so dde-file-manager’s service watcher treats the shutdown as an index-backend failure and switches the UI to an error state instead of treating the service as available for on-demand activation.

Make the client recover cleanly from intentional idle unregistration, or change the shutdown/availability signaling so idle exit is not reported as a backend failure.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at line 76:

**Idle shutdown appears as backend failure**

When the idle timer expires while dde-file-manager is watching the index service, the service unregisters its names on a normal idle exit, so dde-file-manager’s service watcher treats the shutdown as an index-backend failure and switches the UI to an error state instead of treating the service as available for on-demand activation.

Make the client recover cleanly from intentional idle unregistration, or change the shutdown/availability signaling so idle exit is not reported as a backend failure.

QCoreApplication::quit();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · TextIndex activation cannot relaunch binary

When the process has auto-exited and a caller next requests the TextIndex service, after this code quits the process, a TextIndex request asks D-Bus to activate /usr/bin/deepin-anything-index, but the package installs the executable under /usr/libexec/deepin/deepin-anything-index. Activation fails, leaving the index service unavailable.

Change the D-Bus activation executable path to the installed libexec path, or install the executable at the path named by Exec.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at line 77:

**TextIndex activation cannot relaunch binary**

When the process has auto-exited and a caller next requests the TextIndex service, after this code quits the process, a TextIndex request asks D-Bus to activate `/usr/bin/deepin-anything-index`, but the package installs the executable under `/usr/libexec/deepin/deepin-anything-index`. Activation fails, leaving the index service unavailable.

Change the D-Bus activation executable path to the installed libexec path, or install the executable at the path named by `Exec`.

});
Comment on lines +76 to +78

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Missed changes leave index stale

When filesystem changes occur while monitoring is enabled but no D-Bus activity reaches the service for the configured timeout, unregisterIndexServices() stops filesystem monitoring, and a normal cleanup with no unfinished task leaves the index marked clean. On restart, handleSilentStart() skips the global update for a clean index, so files changed while the service was stopped are absent or stale in search results.

Before an idle exit, persist a dirty/recovery state whenever monitoring was enabled so the next activation reconciles changes missed during downtime.

Prompt for AI agents
In `src/index/idleexitmanager.cpp` at lines 76-78:

**Missed changes leave index stale**

When filesystem changes occur while monitoring is enabled but no D-Bus activity reaches the service for the configured timeout, `unregisterIndexServices()` stops filesystem monitoring, and a normal cleanup with no unfinished task leaves the index marked clean. On restart, `handleSilentStart()` skips the global update for a clean index, so files changed while the service was stopped are absent or stale in search results.

Before an idle exit, persist a dirty/recovery state whenever monitoring was enabled so the next activation reconciles changes missed during downtime.


qDBusAddSpyHook(idleSpyHook);
g_idleTimer->start();
}

} // namespace anything_index
30 changes: 30 additions & 0 deletions src/index/idleexitmanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef IDLEEXITMANAGER_H
#define IDLEEXITMANAGER_H

namespace anything_index {

// Registers a D-Bus spy hook that restarts an idle timer on every D-Bus
// message. When the timer expires (no D-Bus activity for the configured
// number of minutes), unregisters index services and quits the application.
//
// The idle timeout is read from the dconfig key "idle_exit_timeout_minutes"
// in the org.deepin.anything schema (default: 10 minutes). A value of 0
// disables the auto-exit feature entirely.
//
// The service is D-Bus-activated (its .service file points at
// deepin-anything-index), so exiting when idle is safe: the next D-Bus
// call to any index service name will automatically restart the process.
//
// dde-file-manager's AbstractIndexController::keepBackendAlive polls
// IsEnabled every 5 minutes while indexes are enabled, which resets the
// timer and keeps the service alive. When all indexes are disabled the
// keepalive stops, and the service exits after the idle timeout.
void startIdleExitManager();

} // namespace anything_index

#endif // IDLEEXITMANAGER_H
9 changes: 9 additions & 0 deletions src/index/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "serviceentry.h"
#include "idleexitmanager.h"
#include "utils/trustclient.h"

#include <QGuiApplication>

Check warning on line 9 in src/index/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QGuiApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSocketNotifier>

#include <sys/socket.h>
Expand Down Expand Up @@ -132,6 +133,14 @@
return 1;
}

// Exit the process after a configurable idle timeout (dconfig key
// idle_exit_timeout_minutes, default 10 min). The service
// is D-Bus-activated, so the next request to any index service name
// restarts it automatically. dde-file-manager's keepBackendAlive polls
// IsEnabled every 5 minutes while indexes are enabled, which resets the
// idle timer and keeps the service alive.
anything_index::startIdleExitManager();

// Bind the index lifecycle to the daemon: watch the daemon's D-Bus name
// (org.deepin.Anything) on the system bus for unregistration. When the
// daemon stops or crashes its bus name is released — at that point we
Expand Down
Loading