From 334499a3f4d77c70ce3e24543f081e1d50b46521 Mon Sep 17 00:00:00 2001 From: luk1337 Date: Tue, 13 Jul 2021 17:30:38 +0200 Subject: [PATCH] du: Don't fail immediately when directory can't be read (#8719) --- Userland/Utilities/du.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Utilities/du.cpp b/Userland/Utilities/du.cpp index a3314a8db3..4f218c9a0f 100644 --- a/Userland/Utilities/du.cpp +++ b/Userland/Utilities/du.cpp @@ -136,11 +136,13 @@ int print_space_usage(const String& path, const DuOption& du_option, int max_dep return 1; } + int ret = 0; + if (--max_depth >= 0 && S_ISDIR(path_stat.st_mode)) { auto di = Core::DirIterator(path, Core::DirIterator::SkipParentAndBaseDir); if (di.has_error()) { - warnln("DirIterator: {}", di.error_string()); - return 1; + warnln("du: cannot read directory '{}': {}", path, di.error_string()); + ret = 1; } while (di.has_next()) { const auto child_path = di.next_full_path(); @@ -193,5 +195,5 @@ int print_space_usage(const String& path, const DuOption& du_option, int max_dep outln("\t{}\t{}", formatted_time, path); } - return 0; + return ret; }