This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 152eb9746bd910df5be4f922f0704c54aee30ba3
Author: zhannngchen <[email protected]>
AuthorDate: Tue Feb 6 19:03:59 2024 +0800

    [fix](gc) process exception while iteratoring directory (#30850)
---
 be/src/io/fs/local_file_system.cpp | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/be/src/io/fs/local_file_system.cpp 
b/be/src/io/fs/local_file_system.cpp
index fc2008a6778..cf28c7caa09 100644
--- a/be/src/io/fs/local_file_system.cpp
+++ b/be/src/io/fs/local_file_system.cpp
@@ -203,23 +203,30 @@ 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 localfs_error(e.code(), fmt::format("failed to list {}, error 
message: {}",
+                                                   dir.native(), e.what()));
     }
     if (ec) {
         return localfs_error(ec, fmt::format("failed to list {}", 
dir.native()));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to