Skip to content

Commit

Permalink
add file exists check (#36628)
Browse files Browse the repository at this point in the history
* add file check

* add ut
  • Loading branch information
jiweibo committed Oct 23, 2021
1 parent 3cb6f65 commit 425db7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions paddle/fluid/inference/utils/io_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ void SerializeShapeRangeInfo(
void DeserializeShapeRangeInfo(
const std::string &path, paddle::inference::proto::ShapeRangeInfos *info) {
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 =
new google::protobuf::io::FileInputStream(fd);
google::protobuf::TextFormat::Parse(is, info);
Expand Down
4 changes: 4 additions & 0 deletions paddle/fluid/inference/utils/io_utils_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,8 @@ TEST(shape_info_io, read_and_write) {
std::vector<std::string> names{"test1"};
paddle::inference::UpdateShapeRangeInfo(path, min_shape, max_shape, opt_shape,
names);

ASSERT_THROW(paddle::inference::DeserializeShapeRangeInfo(
"no_exists_file", &min_shape, &max_shape, &opt_shape);
, paddle::platform::EnforceNotMet);
}

0 comments on commit 425db7c

Please sign in to comment.