From 12daecf72d005bd1ce48a695e6cedb415c377261 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Thu, 3 Feb 2022 15:12:53 +0100 Subject: [PATCH] Utilities: Fix du to print stats for regular files du will not print anything until `-a` option was provided. Fix the behaviour by taking into account the `-a` option only when a directory is given as the input. --- Userland/Utilities/du.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Utilities/du.cpp b/Userland/Utilities/du.cpp index bb0efd7ab3..34771db5a8 100644 --- a/Userland/Utilities/du.cpp +++ b/Userland/Utilities/du.cpp @@ -35,7 +35,7 @@ struct DuOption { }; static ErrorOr parse_args(Main::Arguments arguments, Vector& files, DuOption& du_option, int& max_depth); -static ErrorOr print_space_usage(const String& path, const DuOption& du_option, int max_depth); +static ErrorOr print_space_usage(const String& path, const DuOption& du_option, int max_depth, bool inside_dir = false); ErrorOr serenity_main(Main::Arguments arguments) { @@ -118,7 +118,7 @@ ErrorOr parse_args(Main::Arguments arguments, Vector& files, DuOpt return {}; } -ErrorOr print_space_usage(const String& path, const DuOption& du_option, int max_depth) +ErrorOr print_space_usage(const String& path, const DuOption& du_option, int max_depth, bool inside_dir) { struct stat path_stat = TRY(Core::System::lstat(path.characters())); off_t directory_size = 0; @@ -132,7 +132,7 @@ ErrorOr print_space_usage(const String& path, const DuOption& du_option, while (di.has_next()) { const auto child_path = di.next_full_path(); - directory_size += TRY(print_space_usage(child_path, du_option, max_depth)); + directory_size += TRY(print_space_usage(child_path, du_option, max_depth, true)); } } @@ -148,7 +148,7 @@ ErrorOr print_space_usage(const String& path, const DuOption& du_option, size = path_stat.st_blocks * block_size; } - if (!du_option.all && !is_directory) + if (inside_dir && !du_option.all && !is_directory) return size; if (is_directory)