|
|
@@ -340,15 +340,24 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::string RealPath(const char |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
void PathValidErrReport(const std::string &file_path, const std::string &atc_param, const std::string &reason) { |
|
|
|
if (!atc_param.empty()) { |
|
|
|
REPORT_INPUT_ERROR("E10001", std::vector<std::string>({"parameter", "value", "reason"}), |
|
|
|
std::vector<std::string>({atc_param, file_path, reason})); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s] invalid, reason:%s", file_path.c_str(), reason.c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInputPathValid(const std::string &file_path, |
|
|
|
const std::string &atc_param) { |
|
|
|
// The specified path is empty |
|
|
|
std::map<std::string, std::string> args_map; |
|
|
|
if (file_path.empty()) { |
|
|
|
if (atc_param != "") { |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10004", {"parameter"}, {atc_param}); |
|
|
|
if (!atc_param.empty()) { |
|
|
|
REPORT_INPUT_ERROR("E10004", std::vector<std::string>({"parameter"}), std::vector<std::string>({atc_param})); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Param file_path is empty, check invalid"); |
|
|
|
REPORT_INNER_ERROR("E19999", "Param file_path is empty, check invalid."); |
|
|
|
} |
|
|
|
GELOGW("Input parameter %s is empty.", file_path.c_str()); |
|
|
|
return false; |
|
|
@@ -356,13 +365,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInputPathValid(const |
|
|
|
std::string real_path = RealPath(file_path.c_str()); |
|
|
|
// Unable to get absolute path (does not exist or does not have permission to access) |
|
|
|
if (real_path.empty()) { |
|
|
|
if (atc_param != "") { |
|
|
|
std::string reason = "realpath error, errmsg:" + std::string(strerror(errno)); |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10001", {"parameter", "value", "reason"}, |
|
|
|
{atc_param, file_path, reason}); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s]'s realpath is empty, errmsg[%s]", file_path.c_str(), strerror(errno)); |
|
|
|
} |
|
|
|
std::string reason = "realpath error, errmsg:" + std::string(strerror(errno)); |
|
|
|
PathValidErrReport(file_path, atc_param, reason); |
|
|
|
GELOGW("Path[%s]'s realpath is empty, errmsg[%s]", file_path.c_str(), strerror(errno)); |
|
|
|
return false; |
|
|
|
} |
|
|
@@ -378,23 +382,12 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInputPathValid(const |
|
|
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( |
|
|
|
!ValidateStr(real_path, mode), |
|
|
|
if (atc_param != "") { |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10001", {"parameter", "value", "reason"}, |
|
|
|
{atc_param, real_path, kPathValidReason}); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s] has invalid char, %s", file_path.c_str(), kPathValidReason); |
|
|
|
} |
|
|
|
PathValidErrReport(file_path, atc_param, kPathValidReason); |
|
|
|
return false, "Invalid value for %s[%s], %s.", atc_param.c_str(), real_path.c_str(), kPathValidReason); |
|
|
|
|
|
|
|
// The absolute path points to a file that is not readable |
|
|
|
if (mmAccess2(real_path.c_str(), M_R_OK) != EN_OK) { |
|
|
|
if (atc_param != "") { |
|
|
|
std::string reason = "cat not access, errmsg:" + std::string(strerror(errno)); |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10001", {"parameter", "value", "reason"}, |
|
|
|
{atc_param, file_path, reason}); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s] can't acccess, errmsg:%s", file_path.c_str(), strerror(errno)); |
|
|
|
} |
|
|
|
PathValidErrReport(file_path, atc_param, "cat not access, errmsg:" + std::string(strerror(errno))); |
|
|
|
GELOGW("Read file[%s] failed, errmsg[%s]", file_path.c_str(), strerror(errno)); |
|
|
|
return false; |
|
|
|
} |
|
|
@@ -406,10 +399,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const |
|
|
|
const std::string &atc_param) { |
|
|
|
// The specified path is empty |
|
|
|
if (file_path.empty()) { |
|
|
|
if (atc_param != "") { |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10004", {"parameter"}, {atc_param}); |
|
|
|
if (!atc_param.empty()) { |
|
|
|
REPORT_INPUT_ERROR("E10004", std::vector<std::string>({"parameter"}), std::vector<std::string>({atc_param})); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Param file_path is empty, check invalid"); |
|
|
|
REPORT_INNER_ERROR("E19999", "Param file_path is empty, check invalid."); |
|
|
|
} |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10004", {"parameter"}, {atc_param}); |
|
|
|
GELOGW("Input parameter's value is empty."); |
|
|
@@ -417,17 +410,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const |
|
|
|
} |
|
|
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path.c_str()) >= MMPA_MAX_PATH, |
|
|
|
if (atc_param != "") { |
|
|
|
std::string reason = "len is too long, it must be less than " + |
|
|
|
std::to_string(MMPA_MAX_PATH); |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage( |
|
|
|
"E10001", {"parameter", "value", "reason"}, |
|
|
|
{atc_param, file_path, reason}); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s] len is too long, it must be less than %d", |
|
|
|
file_path.c_str(), MMPA_MAX_PATH); |
|
|
|
} |
|
|
|
return "", "Path[%s] len is too long, it must be less than %d", file_path.c_str(), |
|
|
|
std::string reason = "len is too long, it must be less than " + |
|
|
|
std::to_string(MMPA_MAX_PATH); |
|
|
|
PathValidErrReport(file_path, atc_param, reason); |
|
|
|
return false, "Path[%s] len is too long, it must be less than %d", file_path.c_str(), |
|
|
|
MMPA_MAX_PATH); |
|
|
|
|
|
|
|
// A regular matching expression to verify the validity of the input file path |
|
|
@@ -441,12 +427,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const |
|
|
|
|
|
|
|
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( |
|
|
|
!ValidateStr(file_path, mode), |
|
|
|
if (atc_param != "") { |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10001", {"parameter", "value", "reason"}, |
|
|
|
{atc_param, file_path, kPathValidReason}); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s] has invalid char, %s", file_path.c_str(), kPathValidReason); |
|
|
|
} |
|
|
|
PathValidErrReport(file_path, atc_param, kPathValidReason); |
|
|
|
return false, "Invalid value for %s[%s], %s.", atc_param.c_str(), file_path.c_str(), kPathValidReason); |
|
|
|
|
|
|
|
std::string real_path = RealPath(file_path.c_str()); |
|
|
@@ -454,13 +435,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const |
|
|
|
if (!real_path.empty()) { |
|
|
|
// File is not readable or writable |
|
|
|
if (mmAccess2(real_path.c_str(), M_W_OK | M_F_OK) != EN_OK) { |
|
|
|
if (atc_param != "") { |
|
|
|
std::string reason = "cat not access, errmsg:" + std::string(strerror(errno)); |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10001", {"parameter", "value", "reason"}, |
|
|
|
{atc_param, file_path, reason}); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s] can't acccess, errmsg:%s", file_path.c_str(), strerror(errno)); |
|
|
|
} |
|
|
|
PathValidErrReport(file_path, atc_param, "cat not access, errmsg:" + std::string(strerror(errno))); |
|
|
|
GELOGW("Write file[%s] failed, errmsg[%s]", real_path.c_str(), strerror(errno)); |
|
|
|
return false; |
|
|
|
} |
|
|
@@ -479,12 +454,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const |
|
|
|
std::string prefix_path = std::string(file_path).substr(0, static_cast<size_t>(path_split_pos)); |
|
|
|
// Determine whether the specified path is valid by creating the path |
|
|
|
if (CreateDirectory(prefix_path) != 0) { |
|
|
|
if (atc_param != "") { |
|
|
|
ErrorManager::GetInstance().ATCReportErrMessage("E10001", {"parameter", "value", "reason"}, |
|
|
|
{atc_param, file_path, "Can not create directory"}); |
|
|
|
} else { |
|
|
|
REPORT_INNER_ERROR("E19999", "Path[%s] Can not create directory", file_path.c_str()); |
|
|
|
} |
|
|
|
PathValidErrReport(file_path, atc_param, "Can not create directory"); |
|
|
|
GELOGW("Can not create directory[%s].", file_path.c_str()); |
|
|
|
return false; |
|
|
|
} |
|
|
|