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
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
deepin-anything (7.0.26) unstable; urgency=medium

* feat: Add pinyin acronym to file index
* feat: Refactor VFS unnamed device file handling
* feat: Update pinyin processing and indexing
* fix: Fix fail to create symbolic links for index entry point

-- wangrong <wangrong@uniontech.com> Tue, 02 Sep 2025 18:48:01 +0800

deepin-anything (7.0.25) unstable; urgency=medium

* refactor: Update installation paths for deepin-anything services
Expand Down
54 changes: 39 additions & 15 deletions src/daemon/src/core/file_index_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ DocumentPtr create_document(const file_record& record) {
doc->add(newLucene<NumericField>(MODIFY_TIME_FIELD)->setLongValue(record.modify_time));
doc->add(newLucene<NumericField>(FILE_SIZE_FIELD)->setLongValue(record.file_size));
doc->add(newLucene<Field>(PINYIN_FIELD,
StringUtils::toUnicode(record.file_name_pinyin),
Field::STORE_YES, Field::INDEX_NOT_ANALYZED));
StringUtils::toLower(StringUtils::toUnicode(record.file_name_pinyin)),
Field::STORE_YES, Field::INDEX_ANALYZED));
doc->add(newLucene<Field>(PINYIN_ACRONYM_FIELD,
StringUtils::toUnicode(record.file_name_pinyin_acronym),
Field::STORE_YES, Field::INDEX_NOT_ANALYZED));
StringUtils::toLower(StringUtils::toUnicode(record.file_name_pinyin_acronym)),
Field::STORE_YES, Field::INDEX_ANALYZED));

doc->add(newLucene<Field>(IS_HIDDEN_FIELD,
(record.is_hidden ? L"Y" : L"N"),
Expand Down Expand Up @@ -487,25 +487,49 @@ void file_index_manager::try_refresh_reader(bool nrt) {
}
}

void file_index_manager::prepare_index() {
spdlog::info("Preparing index...");
static void create_index_entry_point(const std::string &volatile_index_directory) {
std::error_code ec;

std::string index_entry_point = std::string(g_get_user_runtime_dir()) + "/deepin-anything-server";

if (volatile_index_directory_ != index_entry_point) {
// create symbolic links for index entry point
if (std::filesystem::exists(index_entry_point)) {
std::filesystem::remove_all(index_entry_point);
}
std::filesystem::create_directory_symlink(volatile_index_directory_, index_entry_point, ec);
if (volatile_index_directory == index_entry_point)
return;

// remove index entry point if exists
// symlink is removed, not its target
std::filesystem::remove_all(index_entry_point, ec);

// create volatile index directory if not exists
ec.clear();
bool volatile_index_directory_exists = std::filesystem::exists(volatile_index_directory, ec);
if (ec) {
spdlog::error("Failed to check volatile index directory: {}, quit", ec.message());
exit(APP_QUIT_CODE);
}
if (!volatile_index_directory_exists) {
ec.clear();
std::filesystem::create_directory(volatile_index_directory, ec);
if (ec) {
spdlog::error("Failed to create symbolic link from {} to {}: {}, quit",
index_entry_point, volatile_index_directory_, ec.message());
spdlog::error("Failed to create volatile index directory: {}, quit", ec.message());
exit(APP_QUIT_CODE);
}
}

// create symbolic links for index entry point
ec.clear();
std::filesystem::create_directory_symlink(volatile_index_directory, index_entry_point, ec);
if (ec) {
spdlog::error("Failed to create symbolic link from {} to {}: {}, quit",
index_entry_point, volatile_index_directory, ec.message());
exit(APP_QUIT_CODE);
}
}

void file_index_manager::prepare_index() {
spdlog::info("Preparing index...");
std::error_code ec;

create_index_entry_point(volatile_index_directory_);

if (persistent_index_directory_ == volatile_index_directory_) {
spdlog::info("Persistent index directory is the same as volatile index directory, skip prepare");
return;
Expand Down
8 changes: 8 additions & 0 deletions src/daemon/src/core/pinyin_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ void pinyin_processor::convert_to_pinyin(const std::string& sentence, std::strin

pinyin_full = std::move(pinyin_english);
pinyin_acronym = std::move(pinyin_acronym_english);

// remove space in pinyin_full and pinyin_acronym
pinyin_full.erase(std::remove_if(pinyin_full.begin(), pinyin_full.end(), [](unsigned char c) {
return std::isspace(c);
}), pinyin_full.end());
pinyin_acronym.erase(std::remove_if(pinyin_acronym.begin(), pinyin_acronym.end(), [](unsigned char c) {
return std::isspace(c);
}), pinyin_acronym.end());
}

unsigned int pinyin_processor::hex_to_dec(const std::string& hex_str) {
Expand Down
7 changes: 4 additions & 3 deletions src/server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#define MAX_MINOR 255

#define VFS_UNNAMED_DEVICE_FILE "/sys/kernel/vfs_monitor/vfs_unnamed_devices"

static GList *get_unnamed_device_by_fstype (GStrv fstypes)
{
GList *devices = NULL;
Expand Down Expand Up @@ -57,21 +59,20 @@ static GList *get_unnamed_device_by_fstype (GStrv fstypes)

static void write_vfs_unnamed_device(const char *str)
{
FILE *file = fopen("/sys/kernel/vfs_monitor/vfs_unnamed_devices", "w");
FILE *file = fopen(VFS_UNNAMED_DEVICE_FILE, "w");
if (!file)
return;

fwrite(str, strlen(str), 1, file);
fclose(file);
g_message("write_vfs_unnamed_device: %s", str);
}

static GList *read_vfs_unnamed_device(GError **error)
{
GList *devices = NULL;

g_autofree char *content = NULL;
if (!g_file_get_contents("/sys/kernel/vfs_monitor/vfs_unnamed_devices", &content, NULL, error)) {
if (!g_file_get_contents(VFS_UNNAMED_DEVICE_FILE, &content, NULL, error)) {
return NULL;
}

Expand Down
Loading