Skip to content

Commit 1d25ee9

Browse files
hzhyhx1117pymumu
authored andcommitted
Driver: replace use json operator <<
Signed-off-by: howe <hzhyhx1117@163.com>
1 parent c6f4441 commit 1d25ee9

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/libmodelbox/base/drivers/driver.cc

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,16 @@ Status Drivers::GatherScanInfo(const std::string &scan_path) {
520520
}
521521

522522
nlohmann::json dump_json;
523-
scan_info_file >> dump_json;
523+
try {
524+
std::string ss((std::istreambuf_iterator<char>(scan_info_file)),
525+
std::istreambuf_iterator<char>());
526+
dump_json = nlohmann::json::parse(ss);
527+
528+
} catch (const std::exception &e) {
529+
auto err_msg = "gather scan info failed, err: " + std::string(e.what());
530+
MBLOG_ERROR << err_msg;
531+
return {STATUS_FAULT, err_msg};
532+
}
524533

525534
auto driver_json_arr = dump_json["scan_drivers"];
526535
for (auto &driver_info : driver_json_arr) {
@@ -555,8 +564,22 @@ void Drivers::FillCheckInfo(std::string &file_check_node,
555564
std::unordered_map<std::string, bool> &file_map,
556565
int64_t &ld_cache_time) {
557566
std::ifstream scan_info(DEFAULT_SCAN_INFO);
567+
if (!scan_info.is_open()) {
568+
MBLOG_ERROR << "open " << DEFAULT_SCAN_INFO << " failed.";
569+
return;
570+
}
571+
558572
nlohmann::json dump_json;
559-
scan_info >> dump_json;
573+
try {
574+
std::string ss((std::istreambuf_iterator<char>(scan_info)),
575+
std::istreambuf_iterator<char>());
576+
dump_json = nlohmann::json::parse(ss);
577+
} catch (const std::exception &e) {
578+
MBLOG_ERROR << "filee check info parse " << DEFAULT_SCAN_INFO
579+
<< " failed, err: " << e.what();
580+
return;
581+
}
582+
560583
file_check_node = dump_json["check_code"];
561584
ld_cache_time = dump_json["ld_cache_time"];
562585
auto driver_json_arr = dump_json["scan_drivers"];
@@ -671,10 +694,19 @@ void Drivers::PrintScanResults(const std::string &scan_path) {
671694
std::ifstream scan_info_file(scan_path);
672695
if (!scan_info_file.is_open()) {
673696
MBLOG_ERROR << "Open file " << scan_path << " for read failed";
697+
return;
674698
}
675699

676700
nlohmann::json dump_json;
677-
scan_info_file >> dump_json;
701+
try {
702+
std::string ss((std::istreambuf_iterator<char>(scan_info_file)),
703+
std::istreambuf_iterator<char>());
704+
dump_json = nlohmann::json::parse(ss);
705+
706+
} catch (const std::exception &e) {
707+
MBLOG_ERROR << "print scan result failed, err: " << e.what();
708+
return;
709+
}
678710

679711
nlohmann::json dump_driver_json_arr = nlohmann::json::array();
680712
dump_driver_json_arr = dump_json["scan_drivers"];

thirdparty/CMake/local-package.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ExternalProject_Add(
8585
# nlohmann json
8686
ExternalProject_Add(
8787
nlohmann
88-
URL @LOCAL_PACKAGE_PATH@/v3.7.3.tar.gz
88+
URL @LOCAL_PACKAGE_PATH@/json-3.10.5.tar.gz
8989
SOURCE_DIR ${THIRDPARTY_DOWNLOAD_DIR}/nlohmann
9090
CONFIGURE_COMMAND ""
9191
BUILD_COMMAND ""

thirdparty/CMake/pre-download.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (NOT @USE_CN_MIRROR@)
3333
set(TINYLOG_DOWNLOAD_URL "https://github.com/pymumu/tinylog/archive/refs/tags/v1.6.zip")
3434
set(PYBIND11_DOWNLOAD_URL "https://github.com/pybind/pybind11/archive/refs/tags/v2.9.1.zip")
3535
set(TOML11_DOWNLOAD_URL "https://github.com/ToruNiina/toml11/archive/refs/tags/v3.7.1.zip")
36-
set(NLOHMANN_DOWNLOAD_URL "https://github.com/nlohmann/json/releases/download/v3.7.3/include.zip")
36+
set(NLOHMANN_DOWNLOAD_URL "https://github.com/nlohmann/json/releases/download/v3.10.5/include.zip")
3737
set(CPP_HTTPLIB_DOWNLOAD_URL "https://github.com/yhirose/cpp-httplib/archive/refs/tags/v0.10.4.zip")
3838
set(APIGW_CPP_SDK_DOWNLOAD_URL "https://github.com/modelbox-ai/modelbox-binary/releases/download/BinaryArchive/APIGW-cpp-sdk.zip")
3939
set(MODELBOX_WEBUI_DOWNLOAD_URL "https://github.com/modelbox-ai/modelbox-webui/archive/refs/tags/0.0.4.zip")
@@ -44,7 +44,7 @@ else()
4444
set(TINYLOG_DOWNLOAD_URL "https://download.fastgit.org/pymumu/tinylog/archive/refs/tags/v1.6.zip")
4545
set(PYBIND11_DOWNLOAD_URL "https://gitcode.net/mirrors/pybind/pybind11/-/archive/v2.9.1/pybind11-v2.9.1.zip")
4646
set(TOML11_DOWNLOAD_URL "https://download.fastgit.org/ToruNiina/toml11/archive/refs/tags/v3.7.1.zip")
47-
set(NLOHMANN_DOWNLOAD_URL "https://gitcode.net/mirrors/nlohmann/json/-/archive/v3.7.3/json-v3.7.3.zip")
47+
set(NLOHMANN_DOWNLOAD_URL "https://gitcode.net/mirrors/nlohmann/json/-/archive/v3.10.5/json-v3.10.5.zip")
4848
set(CPP_HTTPLIB_DOWNLOAD_URL "https://gitcode.net/mirrors/yhirose/cpp-httplib/-/archive/v0.10.4/cpp-httplib-v0.10.4.zip")
4949
set(APIGW_CPP_SDK_DOWNLOAD_URL "https://obs.cn-north-1.myhuaweicloud.com/apig-sdk/APIGW-cpp-sdk.zip")
5050
set(MODELBOX_WEBUI_DOWNLOAD_URL "https://gitee.com/modelbox/modelbox-webui/repository/archive/main.zip")

0 commit comments

Comments
 (0)