diff --git a/include/resource_util.h b/include/resource_util.h index de0254ddc9ccd94060b3fc4302547554707daaa4..f01fc978554bed5c2cd8f1e3cb06c5d436777dbb 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 fdc79662c123ef2dfb3f8c5890752dc55008326d..0f2ba4a295453d8f99e01ee04888236510e42148 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 fc3bde2b2da61093ee5de474f40268f2275475b9..e72fa1ed8a560e0f3557681551b5130a0bd3d79c 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 96d25de32d1b86c41a2ed75f0277c6bedffdbdd8..0600f4efd92e68e3250724aca5ba32020af85fc8 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; +} } } }