From c0ad24b0c2a5271a873d4984ed237cd89085d027 Mon Sep 17 00:00:00 2001 From: xiekaiming Date: Thu, 3 Nov 2022 17:39:12 +0800 Subject: [PATCH 1/6] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0UT=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0etc=E7=9B=AE=E5=BD=95=202.=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B5=84=E6=96=99=203.=20=E4=BC=98=E5=8C=96G?= =?UTF-8?q?etOpkeyPath=E9=80=BB=E8=BE=91=204.=20=E4=BC=98=E5=8C=96napi?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiekaiming --- README.md | 7 +++++- README_zh.md | 7 +++++- .../config_policy/src/config_policy_utils.c | 6 ++--- interfaces/kits/js/src/config_policy_napi.cpp | 6 ++--- test/resource/ohos_test.xml | 22 +++++++++---------- test/unittest/config_policy_utils_test.cpp | 18 +++++++-------- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 79663ff..40a4164 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,14 @@ Call the APIs of the config policy to obtain the configuration directories at di ``` #include "config_policy_utils.h" -const char *testPathSuffix = "user.xml"; // Set the name of the configuration file. +CfgDir *cfgDir = GetCfgDirList(); // Obtain a list of configuration directories + +const char *testPathSuffix = "etc/xml/user.xml"; // Set the relative path of the configuration file. char buf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFile(testPathSuffix, buf, MAX_PATH_LEN); // Obtain the path of the configuration file with the highest priority. + +CfgFiles *cfgFiles = GetCfgFiles(testPathSuffix); // Obtain the all path of the configuration file. + ``` ## Constraints diff --git a/README_zh.md b/README_zh.md index ae7d939..6abf8cf 100644 --- a/README_zh.md +++ b/README_zh.md @@ -38,9 +38,14 @@ ``` #include "config_policy_utils.h" -const char *testPathSuffix = "user.xml"; //设置配置文件名称 +CfgDir *cfgDir = GetCfgDirList(); //获取配置层级目录列表 + +const char *testPathSuffix = "etc/xml/user.xml"; //设置配置文件相对路径及文件名 char buf[MAX_PATH_LEN] = {0}; char *filePath = GetOneCfgFile(testPathSuffix, buf, MAX_PATH_LEN); //获取最高优先级的配置文件路径 + +CfgFiles *cfgFiles = GetCfgFiles(testPathSuffix); //获取所有配置层级的配置文件路径 + ``` ## 约束 diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index 92b7c45..aa6d2e1 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -98,9 +98,9 @@ static char *GetOpkeyPath(int type) opKeyName = CUST_OPKEY1; } else { unsigned int len = 0; - if (SystemGetParameter(CUST_OPKEY0, NULL, &len) == 0 && len > 0) { + if (SystemGetParameter(CUST_OPKEY0, NULL, &len) == 0 && len > 3) { opKeyName = CUST_OPKEY0; - } else if (SystemGetParameter(CUST_OPKEY1, NULL, &len) == 0 && len > 0) { + } else if (SystemGetParameter(CUST_OPKEY1, NULL, &len) == 0 && len > 3) { opKeyName = CUST_OPKEY1; } } @@ -177,7 +177,7 @@ static char *GetFollowXRule(const char *relPath, int *mode) item++; // skip delim ':', goto ":relPath,mode[,extra][:]" char *endItem = strchr(item, SEP_FOR_X_RULE); char *nextItem = endItem + 1; - while (endItem && nextItem && *nextItem == '-') { + while (endItem && *nextItem == '-') { endItem = strchr(nextItem, SEP_FOR_X_RULE); nextItem = endItem + 1; } diff --git a/interfaces/kits/js/src/config_policy_napi.cpp b/interfaces/kits/js/src/config_policy_napi.cpp index 81287eb..3a5c833 100644 --- a/interfaces/kits/js/src/config_policy_napi.cpp +++ b/interfaces/kits/js/src/config_policy_napi.cpp @@ -60,7 +60,7 @@ napi_value ConfigPolicyNapi::NAPIGetOneCfgFile(napi_env env, napi_callback_info auto asyncContext = std::make_unique(); ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]); - if (argc == ARGS_SIZE_TWO) { + if (argc >= ARGS_SIZE_TWO) { bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); if (!matchFlag) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The second parameter must be Callback."); @@ -84,7 +84,7 @@ napi_value ConfigPolicyNapi::NAPIGetCfgFiles(napi_env env, napi_callback_info in auto asyncContext = std::make_unique(); ParseRelPath(env, asyncContext->relPath_, argv[ARR_INDEX_ZERO]); - if (argc == ARGS_SIZE_TWO) { + if (argc >= ARGS_SIZE_TWO) { bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ONE], napi_function); if (!matchFlag) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The second parameter must be Callback."); @@ -103,7 +103,7 @@ napi_value ConfigPolicyNapi::NAPIGetCfgDirList(napi_env env, napi_callback_info napi_get_cb_info(env, info, &argc, argv, &thisVar, &data); auto asyncContext = std::make_unique(); - if (argc == ARGS_SIZE_ONE) { + if (argc >= ARGS_SIZE_ONE) { bool matchFlag = MatchValueType(env, argv[ARR_INDEX_ZERO], napi_function); if (!matchFlag) { return ThrowNapiError(env, PARAM_ERROR, "Parameter error. The first parameter must be Callback."); diff --git a/test/resource/ohos_test.xml b/test/resource/ohos_test.xml index d3c9f67..40ee64a 100644 --- a/test/resource/ohos_test.xml +++ b/test/resource/ohos_test.xml @@ -19,28 +19,28 @@