diff options
author | Martijn Coenen <maco@google.com> | 2019-05-01 16:43:49 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-05-01 16:43:49 +0000 |
commit | e5f112b1e9cce218109ec7baad986fddd07ea13c (patch) | |
tree | 398d0fde0794b9a640554346d1ce8508d6fd84a7 | |
parent | c4caf569e2384383bf121b32d3b2dd7397fef1c4 (diff) | |
parent | 809c3638f6a4f8983b33ad7fa8ac21cfc97463e9 (diff) | |
download | apex-e5f112b1e9cce218109ec7baad986fddd07ea13c.tar.gz |
Merge "Make sure ReadDir() can't throw exceptions." into qt-dev
-rw-r--r-- | apexd/apexd_utils.h | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/apexd/apexd_utils.h b/apexd/apexd_utils.h index 7bc9c86b..ff17dac4 100644 --- a/apexd/apexd_utils.h +++ b/apexd/apexd_utils.h @@ -95,11 +95,21 @@ StatusOr<std::vector<std::string>> ReadDir(const std::string& path, } std::vector<std::string> ret; - for (const auto& entry : fs::directory_iterator(file_path)) { - if (!fn(entry)) { - continue; + auto iter = fs::directory_iterator(file_path, ec); + if (ec) { + return StatusOr<std::vector<std::string>>::MakeError( + StringLog() << "Can't open " << path << " for reading: " << ec); + } + while (iter != fs::end(iter)) { + if (fn(*iter)) { + ret.push_back(file_path.string() + "/" + + iter->path().filename().string()); + } + iter = iter.increment(ec); + if (ec) { + return StatusOr<std::vector<std::string>>::MakeError( + StringLog() << "Failed to iterate " << path << ": " << ec); } - ret.push_back(file_path.string() + "/" + entry.path().filename().string()); } return StatusOr<std::vector<std::string>>(std::move(ret)); |