未验证 提交 425db7c8 编写于 作者: W Wilber 提交者: GitHub

add file exists check (#36628)

* add file check

* add ut
上级 3cb6f65e
...@@ -197,6 +197,9 @@ void SerializeShapeRangeInfo( ...@@ -197,6 +197,9 @@ void SerializeShapeRangeInfo(
void DeserializeShapeRangeInfo( void DeserializeShapeRangeInfo(
const std::string &path, paddle::inference::proto::ShapeRangeInfos *info) { const std::string &path, paddle::inference::proto::ShapeRangeInfos *info) {
int fd = open(path.c_str(), O_RDONLY); int fd = open(path.c_str(), O_RDONLY);
if (fd == -1) {
PADDLE_THROW(platform::errors::NotFound("File [%s] is not found.", path));
}
google::protobuf::io::FileInputStream *is = google::protobuf::io::FileInputStream *is =
new google::protobuf::io::FileInputStream(fd); new google::protobuf::io::FileInputStream(fd);
google::protobuf::TextFormat::Parse(is, info); google::protobuf::TextFormat::Parse(is, info);
......
...@@ -118,4 +118,8 @@ TEST(shape_info_io, read_and_write) { ...@@ -118,4 +118,8 @@ TEST(shape_info_io, read_and_write) {
std::vector<std::string> names{"test1"}; std::vector<std::string> names{"test1"};
paddle::inference::UpdateShapeRangeInfo(path, min_shape, max_shape, opt_shape, paddle::inference::UpdateShapeRangeInfo(path, min_shape, max_shape, opt_shape,
names); names);
ASSERT_THROW(paddle::inference::DeserializeShapeRangeInfo(
"no_exists_file", &min_shape, &max_shape, &opt_shape);
, paddle::platform::EnforceNotMet);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册