resconfig中ignoreResourcePattern为空时不使用默认过滤规则

Signed-off-by: liduo <liduo29@huawei.com>
This commit is contained in:
liduo
2025-03-29 15:12:50 +08:00
parent d164814108
commit d8d70a2dce
4 changed files with 18 additions and 12 deletions
+6
View File
@@ -275,6 +275,12 @@ public:
*/
static bool AddIgnoreFileRegex(const std::string &regex, 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<std::string, IgnoreType> DEFAULT_IGNORE_FILE_REGEX;
static std::string GetLocaleLimitkey(const KeyParam &KeyParam);
+1 -4
View File
@@ -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) {
+1
View File
@@ -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) {
+10 -8
View File
@@ -41,7 +41,8 @@ const map<string, IgnoreType> ResourceUtil::DEFAULT_IGNORE_FILE_REGEX = {
{ "thumbs\\.db", IgnoreType::IGNORE_ALL },
{ ".+~", IgnoreType::IGNORE_ALL }
};
static std::map<std::string, IgnoreType> userIgnoreFileRegex;
static std::map<std::string, IgnoreType> g_userIgnoreFileRegex;
static bool g_isUseCustomRegex = false;
static std::mutex fileMutex_;
@@ -250,8 +251,8 @@ bool ResourceUtil::IsIgnoreFile(const string &filename, bool isFile)
{
map<string, IgnoreType> 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 &regex, 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;
}
}
}
}