mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
Utilities: Fix du to print stats for regular files
du <filename> 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.
This commit is contained in:
parent
b04528c0de
commit
12daecf72d
1 changed files with 4 additions and 4 deletions
|
@ -35,7 +35,7 @@ struct DuOption {
|
||||||
};
|
};
|
||||||
|
|
||||||
static ErrorOr<void> parse_args(Main::Arguments arguments, Vector<String>& files, DuOption& du_option, int& max_depth);
|
static ErrorOr<void> parse_args(Main::Arguments arguments, Vector<String>& files, DuOption& du_option, int& max_depth);
|
||||||
static ErrorOr<off_t> print_space_usage(const String& path, const DuOption& du_option, int max_depth);
|
static ErrorOr<off_t> print_space_usage(const String& path, const DuOption& du_option, int max_depth, bool inside_dir = false);
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
|
@ -118,7 +118,7 @@ ErrorOr<void> parse_args(Main::Arguments arguments, Vector<String>& files, DuOpt
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<off_t> print_space_usage(const String& path, const DuOption& du_option, int max_depth)
|
ErrorOr<off_t> 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()));
|
struct stat path_stat = TRY(Core::System::lstat(path.characters()));
|
||||||
off_t directory_size = 0;
|
off_t directory_size = 0;
|
||||||
|
@ -132,7 +132,7 @@ ErrorOr<off_t> print_space_usage(const String& path, const DuOption& du_option,
|
||||||
|
|
||||||
while (di.has_next()) {
|
while (di.has_next()) {
|
||||||
const auto child_path = di.next_full_path();
|
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<off_t> print_space_usage(const String& path, const DuOption& du_option,
|
||||||
size = path_stat.st_blocks * block_size;
|
size = path_stat.st_blocks * block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!du_option.all && !is_directory)
|
if (inside_dir && !du_option.all && !is_directory)
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
if (is_directory)
|
if (is_directory)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue