File migrate-to-pcre2.patch of Package deepin-file-manager
diff --git a/3rdparty/fsearch/database_search.c b/3rdparty/fsearch/database_search.c
index e4a7e5d07..0c765e822 100644
--- a/3rdparty/fsearch/database_search.c
+++ b/3rdparty/fsearch/database_search.c
@@ -24,7 +24,9 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <pcre.h>
+
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
#include <fnmatch.h>
#include "database_search.h"
@@ -278,12 +280,15 @@ search_regex_thread(void *user_data)
search_query_t **queries = ctx->queries;
search_query_t *query = queries[0];
const char *error;
- int erroffset;
- pcre *regex = pcre_compile(query->query,
- ctx->search->match_case ? 0 : PCRE_CASELESS,
- &error,
- &erroffset,
- NULL);
+ PCRE2_SIZE erroffset;
+ int errornumber;
+ uint32_t options = ctx->search->match_case ? 0 : PCRE2_CASELESS;
+ pcre2_code *regex = pcre2_compile((PCRE2_SPTR)query->query,
+ PCRE2_ZERO_TERMINATED,
+ options,
+ &errornumber,
+ &erroffset,
+ NULL);
int ovector[OVECCOUNT];
@@ -320,28 +325,28 @@ search_regex_thread(void *user_data)
haystack = node->name;
}
size_t haystack_len = strlen(haystack);
-
- if (pcre_exec(regex, NULL, haystack, haystack_len,
- 0, 0, ovector, OVECCOUNT)
+ pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regex, NULL);
+
+ if (pcre2_match(regex, (PCRE2_SPTR)haystack, haystack_len,
+ 0, 0, match_data, NULL)
>= 0) {
- results[num_results] = node;
- num_results++;
- } else if (ctx->search->enable_py && strlen(node->full_py_name)) {
- if (pcre_exec(regex, NULL, node->first_py_name, strlen(node->first_py_name),
- 0, 0, ovector, OVECCOUNT)
- >= 0) {
- results[num_results] = node;
- num_results++;
- } else if (pcre_exec(regex, NULL, node->full_py_name, strlen(node->full_py_name),
- 0, 0, ovector, OVECCOUNT)
- >= 0) {
- results[num_results] = node;
- num_results++;
+ results[num_results++] = node;
+ } else if (ctx->search->enable_py && strlen(node->full_py_name)) {
+ if (pcre2_match(regex, (PCRE2_SPTR)node->first_py_name,
+ strlen(node->first_py_name),
+ 0, 0, match_data, NULL)
+ >= 0) {
+ results[num_results++] = node;
+ } else if (pcre2_match(regex, (PCRE2_SPTR)node->full_py_name,
+ strlen(node->full_py_name),
+ 0, 0, match_data, NULL)
+ >= 0) {
+ results[num_results++] = node;
}
}
}
ctx->num_results = num_results;
- pcre_free(regex);
+ pcre2_code_free(regex);
}
return NULL;
}
diff --git a/debian/control b/debian/control
index ed45399c0..0f159e692 100644
--- a/debian/control
+++ b/debian/control
@@ -24,7 +24,7 @@ Build-Depends:
libsecret-1-dev,
libpoppler-cpp-dev,
libcryptsetup-dev,
- libpcre3-dev,
+ libpcre2-dev,
libdde-shell-dev (>= 0.0.10),
deepin-desktop-base | deepin-desktop-server | deepin-desktop-device,
qt6-base-dev,
diff --git a/src/plugins/filemanager/dfmplugin-search/CMakeLists.txt b/src/plugins/filemanager/dfmplugin-search/CMakeLists.txt
index 6229e68da..c418b9495 100644
--- a/src/plugins/filemanager/dfmplugin-search/CMakeLists.txt
+++ b/src/plugins/filemanager/dfmplugin-search/CMakeLists.txt
@@ -27,7 +27,7 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(Lucene REQUIRED IMPORTED_TARGET liblucene++ liblucene++-contrib)
pkg_check_modules(Docparser REQUIRED IMPORTED_TARGET docparser)
pkg_check_modules(GLIB REQUIRED glib-2.0)
-pkg_check_modules(PCRE REQUIRED libpcre)
+pkg_check_modules(PCRE REQUIRED libpcre2-8)
# use TextIndex interface
set(DBUS_INTERFACE_FILE "${CMAKE_SOURCE_DIR}/assets/dbus/org.deepin.Filemanager.TextIndex.xml")
diff --git a/src/services/textindex/CMakeLists.txt b/src/services/textindex/CMakeLists.txt
index 87e2cb798..cd08ad2ab 100644
--- a/src/services/textindex/CMakeLists.txt
+++ b/src/services/textindex/CMakeLists.txt
@@ -33,7 +33,7 @@ qt6_add_dbus_adaptor(SRC_FILES ${TextIndex_XML}
pkg_check_modules(Lucene REQUIRED IMPORTED_TARGET liblucene++ liblucene++-contrib)
pkg_check_modules(Docparser REQUIRED IMPORTED_TARGET docparser)
pkg_check_modules(GLIB REQUIRED glib-2.0)
-pkg_check_modules(PCRE REQUIRED libpcre)
+pkg_check_modules(PCRE REQUIRED libpcre2-8)
add_library(${PROJECT_NAME}
SHARED
diff --git a/tests/plugins/filemanager/dfmplugin-search/CMakeLists.txt b/tests/plugins/filemanager/dfmplugin-search/CMakeLists.txt
index cf7445e54..75612f1ca 100644
--- a/tests/plugins/filemanager/dfmplugin-search/CMakeLists.txt
+++ b/tests/plugins/filemanager/dfmplugin-search/CMakeLists.txt
@@ -14,7 +14,7 @@ find_package(Boost REQUIRED
pkg_check_modules(Lucene REQUIRED IMPORTED_TARGET liblucene++ liblucene++-contrib)
pkg_check_modules(Docparser REQUIRED IMPORTED_TARGET docparser)
pkg_check_modules(GLIB REQUIRED glib-2.0)
-pkg_check_modules(PCRE REQUIRED libpcre)
+pkg_check_modules(PCRE REQUIRED libpcre2-8)
# UT文件
file(GLOB_RECURSE UT_CXX_FILE