You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by kx...@apache.org on 2024/02/07 23:49:55 UTC
(doris) branch branch-2.0 updated: [branch-2.0](cherry-pick) process exception while iteratoring directory (#30850) (#30958)
This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 3945f0120a5 [branch-2.0](cherry-pick) process exception while iteratoring directory (#30850) (#30958)
3945f0120a5 is described below
commit 3945f0120a59d1f4b11a066b29746201df0e9a1e
Author: zhannngchen <48...@users.noreply.github.com>
AuthorDate: Thu Feb 8 07:49:48 2024 +0800
[branch-2.0](cherry-pick) process exception while iteratoring directory (#30850) (#30958)
---
be/src/io/fs/local_file_system.cpp | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/be/src/io/fs/local_file_system.cpp b/be/src/io/fs/local_file_system.cpp
index 2574cec3ef4..830a7db77cb 100644
--- a/be/src/io/fs/local_file_system.cpp
+++ b/be/src/io/fs/local_file_system.cpp
@@ -183,23 +183,29 @@ Status LocalFileSystem::list_impl(const Path& dir, bool only_file, std::vector<F
return Status::OK();
}
std::error_code ec;
- for (const auto& entry : std::filesystem::directory_iterator(dir, ec)) {
- if (only_file && !entry.is_regular_file()) {
- continue;
- }
- FileInfo file_info;
- file_info.file_name = entry.path().filename();
- file_info.is_file = entry.is_regular_file(ec);
- if (ec) {
- break;
- }
- if (file_info.is_file) {
- file_info.file_size = entry.file_size(ec);
+ try {
+ for (const auto& entry : std::filesystem::directory_iterator(dir, ec)) {
+ if (only_file && !entry.is_regular_file()) {
+ continue;
+ }
+ FileInfo file_info;
+ file_info.file_name = entry.path().filename();
+ file_info.is_file = entry.is_regular_file(ec);
if (ec) {
break;
}
+ if (file_info.is_file) {
+ file_info.file_size = entry.file_size(ec);
+ if (ec) {
+ break;
+ }
+ }
+ files->push_back(std::move(file_info));
}
- files->push_back(std::move(file_info));
+ } catch (const std::filesystem::filesystem_error& e) {
+ // although `directory_iterator(dir, ec)` does not throw an exception,
+ // it may throw an exception during iterator++, so we need to catch the exception here
+ return Status::IOError("failed to list {}: {}", dir.native(), e.what());
}
if (ec) {
return Status::IOError("failed to list {}: {}", dir.native(), errcode_to_str(ec));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org