From 480ba792e3c144c5046d63ef424dc7042206ceeb Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 23 Jul 2022 18:45:53 +0200 Subject: [PATCH] du: Consolidate all "do not print" conditions All of these conditions should make du just not report the file size individually, but it should still count them into the grand total. In the case of the `--threshold` option, this was actually implemented incorrectly before, as it would report size 0 for files that did not match the threshold. --- Userland/Utilities/du.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Userland/Utilities/du.cpp b/Userland/Utilities/du.cpp index 32b906ec5d..2ffd84d6fa 100644 --- a/Userland/Utilities/du.cpp +++ b/Userland/Utilities/du.cpp @@ -165,15 +165,14 @@ ErrorOr print_space_usage(String const& path, DuOption const& du_option, si size += path_stat.st_size; } - if (inside_dir && !du_option.all && !is_directory) + bool is_beyond_depth = current_depth > du_option.max_depth; + bool is_inner_file = inside_dir && !is_directory; + bool is_outside_threshold = (du_option.threshold > 0 && size < static_cast(du_option.threshold)) || (du_option.threshold < 0 && size > static_cast(-du_option.threshold)); + + // All of these still count towards the full size, they are just not reported on individually. + if (is_beyond_depth || (is_inner_file && !du_option.all) || is_outside_threshold) return size; - if ((du_option.threshold > 0 && size < static_cast(du_option.threshold)) || (du_option.threshold < 0 && size > static_cast(-du_option.threshold))) - return { 0 }; - - if (current_depth > du_option.max_depth) - return { size }; - if (du_option.human_readable) { out("{}", human_readable_size(size)); } else {