修改配置文件获取失败

Signed-off-by: litiangang4 <litiangang4@huawei.com>
This commit is contained in:
litiangang4 2023-06-12 14:13:57 +08:00
parent 73b506a596
commit 14caafd39c
2 changed files with 5 additions and 4 deletions

View File

@ -71,7 +71,7 @@ namespace DistributedHardware {
constexpr const char *EVENT_RUN = "EventRun";
constexpr const char *START_EVENT = "StartEvent";
constexpr const char *COMPONENTSLOAD_PROFILE_PATH =
R"(etc/distributedhardware/distributed_hardware_components_cfg.json)";
"etc/distributedhardware/distributed_hardware_components_cfg.json";
} // namespace DistributedHardware
} // namespace OHOS
#endif

View File

@ -351,12 +351,13 @@ int32_t ComponentLoader::ParseConfig()
int32_t ret;
DHLOGI("ParseConfig start");
char buf[MAX_PATH_LEN] = {0};
char path[PATH_MAX + 1] = {0x00};
char *profilePath = GetOneCfgFile(COMPONENTSLOAD_PROFILE_PATH, buf, MAX_PATH_LEN);
if (profilePath == nullptr) {
DHLOGE("profilePath is null!");
if (strlen(profilePath) == 0 || strlen(profilePath) > PATH_MAX || realpath(profilePath, path) == nullptr) {
DHLOGE("File connicailization failed.");
return ERR_DH_FWK_LOADER_PROFILE_PATH_IS_NULL;
}
std::string componentProfilePath(profilePath);
std::string componentProfilePath(path);
std::string jsonStr = Readfile(componentProfilePath);
if (jsonStr.length() == 0 || jsonStr.size() > MAX_MESSAGE_LEN) {
DHLOGE("ConfigJson size is invalid!");