From c950467d59e9be58fa1d70e1db9df13baaedcbb6 Mon Sep 17 00:00:00 2001 From: liduo Date: Sat, 29 Mar 2025 15:12:50 +0800 Subject: [PATCH] =?UTF-8?q?resconfig=E4=B8=ADignoreResourcePattern?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=B8=8D=E4=BD=BF=E7=94=A8=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=BF=87=E6=BB=A4=E8=A7=84=E5=88=99=20Signed-off-by:?= =?UTF-8?q?=20liduo=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/resource_util.h | 6 ++++++ src/cmd/package_parser.cpp | 5 +---- src/resconfig_parser.cpp | 1 + src/resource_util.cpp | 18 ++++++++++-------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/include/resource_util.h b/include/resource_util.h index de0254d..f01fc97 100644 --- a/include/resource_util.h +++ b/include/resource_util.h @@ -275,6 +275,12 @@ public: */ static bool AddIgnoreFileRegex(const std::string ®ex, IgnoreType ignoreType); + /** + * @brief set whether use custom ignore regex pattern + * @param isUseCustomRegex: true is use custom ignore file regex + */ + static void SetUseCustomIgnoreRegex(const bool &isUseCustomRegex); + private: static const std::map DEFAULT_IGNORE_FILE_REGEX; static std::string GetLocaleLimitkey(const KeyParam &KeyParam); diff --git a/src/cmd/package_parser.cpp b/src/cmd/package_parser.cpp index fdc7966..0f2ba4a 100644 --- a/src/cmd/package_parser.cpp +++ b/src/cmd/package_parser.cpp @@ -479,12 +479,9 @@ uint32_t PackageParser::ParseThread(const std::string &argValue) uint32_t PackageParser::ParseIgnoreFileRegex(const std::string &argValue) { - if (argValue.empty()) { - PrintError(GetError(ERR_CODE_INVALID_IGNORE_FILE).FormatCause(argValue.c_str(), "empty value.")); - return RESTOOL_ERROR; - } std::stringstream in(argValue); std::string regex; + ResourceUtil::SetUseCustomIgnoreRegex(true); while (getline(in, regex, ':')) { bool isSucceed = ResourceUtil::AddIgnoreFileRegex(regex, IgnoreType::IGNORE_ALL); if (!isSucceed) { diff --git a/src/resconfig_parser.cpp b/src/resconfig_parser.cpp index fc3bde2..e72fa1e 100644 --- a/src/resconfig_parser.cpp +++ b/src/resconfig_parser.cpp @@ -205,6 +205,7 @@ uint32_t ResConfigParser::GetIgnorePatterns(const std::string &nodeName, const c PrintError(GetError(ERR_CODE_JSON_NODE_MISSING).FormatCause(nodeName.c_str()).SetPosition(filePath_)); return RESTOOL_ERROR; } + ResourceUtil::SetUseCustomIgnoreRegex(true); HandleBack callback = [](int c, const string &argValue) { bool isSucceed = ResourceUtil::AddIgnoreFileRegex(argValue, IgnoreType::IGNORE_ALL); if (!isSucceed) { diff --git a/src/resource_util.cpp b/src/resource_util.cpp index 96d25de..0600f4e 100644 --- a/src/resource_util.cpp +++ b/src/resource_util.cpp @@ -41,7 +41,8 @@ const map ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = { { "thumbs\\.db", IgnoreType::IGNORE_ALL }, { ".+~", IgnoreType::IGNORE_ALL } }; -static std::map userIgnoreFileRegex; +static std::map g_userIgnoreFileRegex; +static bool g_isUseCustomRegex = false; static std::mutex fileMutex_; @@ -250,8 +251,8 @@ bool ResourceUtil::IsIgnoreFile(const string &filename, bool isFile) { map regexs; std::string regexSources; - if (userIgnoreFileRegex.size() > 0) { - regexs = userIgnoreFileRegex; + if (g_isUseCustomRegex) { + regexs = g_userIgnoreFileRegex; regexSources = "user"; } else { regexs = DEFAULT_IGNORE_FILE_REGEX; @@ -521,19 +522,20 @@ string ResourceUtil::KeyTypeToStr(KeyType type) bool ResourceUtil::AddIgnoreFileRegex(const std::string ®ex, IgnoreType ignoreType) { - if (regex.empty()) { - PrintError(GetError(ERR_CODE_INVALID_IGNORE_FILE).FormatCause(regex.c_str(), "empty value.")); - return false; - } try { std::regex rg(regex); } catch (std::regex_error err) { PrintError(GetError(ERR_CODE_INVALID_IGNORE_FILE).FormatCause(regex.c_str(), err.what())); return false; } - userIgnoreFileRegex[regex] = ignoreType; + g_userIgnoreFileRegex[regex] = ignoreType; return true; } + +void ResourceUtil::SetUseCustomIgnoreRegex(const bool &isUseCustomRegex) +{ + g_isUseCustomRegex = isUseCustomRegex; +} } } } -- Gitee