mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
du: Port to Core::Stream
This commit is contained in:
parent
e08a42acd8
commit
7684e514dd
1 changed files with 7 additions and 8 deletions
|
@ -11,12 +11,11 @@
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/DateTime.h>
|
#include <LibCore/DateTime.h>
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
struct DuOption {
|
struct DuOption {
|
||||||
enum class TimeType {
|
enum class TimeType {
|
||||||
|
@ -55,8 +54,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
ErrorOr<void> parse_args(Main::Arguments arguments, Vector<String>& files, DuOption& du_option)
|
ErrorOr<void> parse_args(Main::Arguments arguments, Vector<String>& files, DuOption& du_option)
|
||||||
{
|
{
|
||||||
bool summarize = false;
|
bool summarize = false;
|
||||||
char const* pattern = nullptr;
|
StringView pattern;
|
||||||
char const* exclude_from = nullptr;
|
StringView exclude_from;
|
||||||
Vector<StringView> files_to_process;
|
Vector<StringView> files_to_process;
|
||||||
|
|
||||||
Core::ArgsParser::Option time_option {
|
Core::ArgsParser::Option time_option {
|
||||||
|
@ -112,11 +111,11 @@ ErrorOr<void> parse_args(Main::Arguments arguments, Vector<String>& files, DuOpt
|
||||||
if (summarize)
|
if (summarize)
|
||||||
du_option.max_depth = 0;
|
du_option.max_depth = 0;
|
||||||
|
|
||||||
if (pattern)
|
if (!pattern.is_empty())
|
||||||
du_option.excluded_patterns.append(pattern);
|
du_option.excluded_patterns.append(pattern);
|
||||||
if (exclude_from) {
|
if (!exclude_from.is_empty()) {
|
||||||
auto file = TRY(Core::File::open(exclude_from, Core::OpenMode::ReadOnly));
|
auto file = TRY(Core::Stream::File::open(exclude_from, Core::Stream::OpenMode::Read));
|
||||||
auto const buff = file->read_all();
|
auto const buff = TRY(file->read_all());
|
||||||
if (!buff.is_empty()) {
|
if (!buff.is_empty()) {
|
||||||
String patterns = String::copy(buff, Chomp);
|
String patterns = String::copy(buff, Chomp);
|
||||||
du_option.excluded_patterns.extend(patterns.split('\n'));
|
du_option.excluded_patterns.extend(patterns.split('\n'));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue