mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-19 19:33:46 -04:00
!222 fix split pattern error
Merge pull request !222 from liduo/fix_ignore_file
This commit is contained in:
@@ -39,6 +39,7 @@ private:
|
||||
uint32_t GetModuleNames(const cJSON *node, int c, HandleBack callback);
|
||||
uint32_t GetBool(const std::string &nodeName, const cJSON *node, int c, HandleBack callback);
|
||||
uint32_t GetNumber(const std::string &nodeName, const cJSON *node, int c, HandleBack callback);
|
||||
uint32_t GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c);
|
||||
cJSON *root_;
|
||||
std::string filePath_;
|
||||
};
|
||||
|
||||
@@ -271,8 +271,9 @@ public:
|
||||
* @brief add ignore file regex pattern
|
||||
* @param regex: the regex pattern
|
||||
* @param ignoreType: the ignore file type
|
||||
* @return if add succeed, return true
|
||||
*/
|
||||
static void AddIgnoreFileRegex(const std::string ®ex, IgnoreType ignoreType);
|
||||
static bool AddIgnoreFileRegex(const std::string ®ex, IgnoreType ignoreType);
|
||||
|
||||
private:
|
||||
static const std::map<std::string, IgnoreType> DEFAULT_IGNORE_FILE_REGEX;
|
||||
|
||||
@@ -486,13 +486,10 @@ uint32_t PackageParser::ParseIgnoreFileRegex(const std::string &argValue)
|
||||
std::stringstream in(argValue);
|
||||
std::string regex;
|
||||
while (getline(in, regex, ':')) {
|
||||
try {
|
||||
std::regex rg(regex);
|
||||
} catch (std::regex_error err) {
|
||||
PrintError(GetError(ERR_CODE_INVALID_IGNORE_FILE).FormatCause(regex.c_str(), err.what()));
|
||||
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(regex, IgnoreType::IGNORE_ALL);
|
||||
if (!isSucceed) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
ResourceUtil::AddIgnoreFileRegex(regex, IgnoreType::IGNORE_ALL);
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ void ResConfigParser::InitFileListCommand(HandleBack callback)
|
||||
Option::COMPRESSED_CONFIG, callback));
|
||||
fileListHandles_.emplace("thread", bind(&ResConfigParser::GetNumber, this, "thread", _1,
|
||||
Option::THREAD, callback));
|
||||
fileListHandles_.emplace("ignoreResourcePattern", bind(&ResConfigParser::GetArray, this, "ignoreResourcePattern",
|
||||
_1, Option::IGNORED_FILE, callback));
|
||||
fileListHandles_.emplace("ignoreResourcePattern", bind(&ResConfigParser::GetIgnorePatterns, this,
|
||||
"ignoreResourcePattern", _1, Option::IGNORED_FILE));
|
||||
}
|
||||
|
||||
uint32_t ResConfigParser::GetString(const std::string &nodeName, const cJSON *node, int c, HandleBack callback)
|
||||
@@ -198,6 +198,25 @@ uint32_t ResConfigParser::GetNumber(const std::string &nodeName, const cJSON *no
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t ResConfigParser::GetIgnorePatterns(const std::string &nodeName, const cJSON *node, int c)
|
||||
{
|
||||
if (!node) {
|
||||
PrintError(GetError(ERR_CODE_JSON_NODE_MISSING).FormatCause(nodeName.c_str()).SetPosition(filePath_));
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
HandleBack callback = [](int c, const string &argValue) {
|
||||
bool isSucceed = ResourceUtil::AddIgnoreFileRegex(argValue, IgnoreType::IGNORE_ALL);
|
||||
if (!isSucceed) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
};
|
||||
if (GetArray(nodeName, node, c, callback) != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -519,9 +519,20 @@ string ResourceUtil::KeyTypeToStr(KeyType type)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ResourceUtil::AddIgnoreFileRegex(const std::string ®ex, IgnoreType ignoreType)
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user