Browse Source

!6399 Check if csv file is open

Merge pull request !6399 from jiangzhiwen/fix/ifstream_is_open
tags/v1.0.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
9758be4719
1 changed files with 6 additions and 0 deletions
  1. +6
    -0
      mindspore/ccsrc/minddata/dataset/engine/datasetops/source/csv_op.cc

+ 6
- 0
mindspore/ccsrc/minddata/dataset/engine/datasetops/source/csv_op.cc View File

@@ -495,6 +495,9 @@ Status CsvOp::LoadFile(const std::string &file, const int64_t start_offset, cons
csv_parser.SetEndOffset(end_offset);
std::ifstream ifs;
ifs.open(file, std::ifstream::in);
if (!ifs.is_open()) {
RETURN_STATUS_UNEXPECTED("Error opening file: " + file);
}
if (column_name_list_.empty()) {
std::string tmp;
getline(ifs, tmp);
@@ -793,6 +796,9 @@ int64_t CsvOp::CountTotalRows(const std::string &file) {
CsvParser csv_parser(0, jagged_buffer_connector_, rows_per_buffer_, field_delim_, column_default_list_);
std::ifstream ifs;
ifs.open(file, std::ifstream::in);
if (!ifs.is_open()) {
return 0;
}
if (column_name_list_.empty()) {
std::string tmp;
getline(ifs, tmp);


Loading…
Cancel
Save