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 @@ -102,6 +102,7 @@ debian/deepin-anything-server.debhelper.log
.cursor/
.specstory/
.cursorindexingignore
.claude/

# kernelmod
src/kernelmod/.Module.symvers.cmd
Expand Down
2 changes: 1 addition & 1 deletion assets/org.deepin.anything.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"visibility": "public"
},
"pic_file_suffix": {
"value": "ani;bmp;gif;ico;jpe;jpeg;jpg;pcx;png;psd;tga;tif;tiff;webp;wmf;svg",
"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":[],
"name": "Pic File Suffix",
Expand Down
58 changes: 57 additions & 1 deletion src/daemon/src/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
#include "utils/string_helper.h"

#include <glib.h>
#include <sstream>

Check warning on line 12 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <sstream> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <gio/gio.h>

Check warning on line 13 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 13 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <gio/gio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <unordered_set>

Check warning on line 14 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 14 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 15 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 15 in src/daemon/src/core/config.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

#define COMMIT_VOLATILE_INDEX_TIMEOUT_DEFAULT 2
#define COMMIT_VOLATILE_INDEX_TIMEOUT_MIN 1
Expand Down Expand Up @@ -252,10 +253,65 @@
g_object_unref(dbus_connection_);
}

static void migrate_index_dir(const std::string& old_dir, const std::string& new_dir) {
std::error_code ec;

// Skip if new directory already exists
if (std::filesystem::exists(new_dir, ec)) {
return;
}

// Skip if old directory doesn't exist
if (!std::filesystem::exists(old_dir, ec)) {
return;
}

spdlog::info("Migrating index from {} to {}", old_dir, new_dir);

// Create parent directory for new location
auto parent_path = std::filesystem::path(new_dir).parent_path();
if (!std::filesystem::exists(parent_path, ec)) {
std::filesystem::create_directories(parent_path, ec);
if (ec) {
spdlog::error("Failed to create parent directory {}: {}", parent_path.string(), ec.message());
return;
}
}

// Move the directory
std::filesystem::rename(old_dir, new_dir, ec);
if (ec) {
spdlog::error("Failed to migrate index directory: {}", ec.message());
// If rename fails (e.g., cross-device), try copy and remove
ec.clear();
std::filesystem::copy(old_dir, new_dir, std::filesystem::copy_options::recursive, ec);
if (ec) {
spdlog::error("Failed to copy index directory: {}", ec.message());
return;
}
ec.clear();
std::filesystem::remove_all(old_dir, ec);
if (ec) {
spdlog::warn("Failed to remove old index directory: {}", ec.message());
}
}

spdlog::info("Index migration completed successfully");
}

event_handler_config Config::make_event_handler_config()
{
event_handler_config config;
config.persistent_index_dir = std::string(g_get_user_cache_dir()) + "/deepin-anything-server";

// Use XDG_DATA_HOME for persistent index storage (instead of XDG_CACHE_HOME)
// This ensures the index survives cache cleaning operations
std::string old_index_dir = std::string(g_get_user_cache_dir()) + "/deepin-anything-server";
std::string new_index_dir = std::string(g_get_user_data_dir()) + "/deepin-anything-server";

// Migrate from old location to new location if needed
migrate_index_dir(old_index_dir, new_index_dir);

config.persistent_index_dir = new_index_dir;
config.volatile_index_dir = config.persistent_index_dir;
config.blacklist_paths = blacklist_paths_;
config.indexing_paths = indexing_paths_;
Expand Down
2 changes: 2 additions & 0 deletions src/daemon/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ int main(int argc, char* argv[]) {
event_listenser listenser;
print_event_handler_config(event_handler_config);
default_event_handler handler(event_handler_config);
// default_event_handler 实例化时, 可能会清空索引目录, 这里重新设置 running 标志
set_running_flag();
listenser.set_handler([&handler](fs_event *event) {
handler.handle(event);
});
Expand Down
5 changes: 5 additions & 0 deletions src/daemon/src/utils/running_flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ void set_running_flag(void)

std::string running_flag_path = get_running_flag_path();

if (g_file_test(running_flag_path.c_str(), G_FILE_TEST_EXISTS)) {
spdlog::debug("Running flag already exists at {}, skipping", running_flag_path);
return;
}

if (!g_file_set_contents(running_flag_path.c_str(), "", -1, nullptr)) {
spdlog::warn("Failed to set running flag at {}: {}", running_flag_path,
strerror(errno));
Expand Down
Loading