diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2023-05-18 15:32:38 +0200 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-05-19 21:36:37 +0200 |
commit | f0ee630ee96f02424ad201c0e49c9c19f457270c (patch) | |
tree | 51dad0db7ab7f9b9d15ed58e081f3d7a850accc4 /Userland/Shell | |
parent | 33026bcefeebb82441d62910572ff98803e146a2 (diff) | |
download | serenity-f0ee630ee96f02424ad201c0e49c9c19f457270c.zip |
Shell: Prefer File::read_until_eof over DeprecatedFile::read_all
Diffstat (limited to 'Userland/Shell')
-rw-r--r-- | Userland/Shell/Shell.cpp | 20 | ||||
-rw-r--r-- | Userland/Shell/main.cpp | 5 |
2 files changed, 16 insertions, 9 deletions
diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp index 7471a8f248..ed8fc81b80 100644 --- a/Userland/Shell/Shell.cpp +++ b/Userland/Shell/Shell.cpp @@ -1077,18 +1077,26 @@ bool Shell::run_file(DeprecatedString const& filename, bool explicitly_invoked) TemporaryChange interactive_change { m_is_interactive, false }; TemporaryChange<Optional<SourcePosition>> source_change { m_source_position, SourcePosition { .source_file = filename, .literal_source_text = {}, .position = {} } }; - auto file_result = Core::DeprecatedFile::open(filename, Core::OpenMode::ReadOnly); - if (file_result.is_error()) { - auto error = DeprecatedString::formatted("'{}': {}", escape_token_for_single_quotes(filename), file_result.error()); + auto file_or_error = Core::File::open(filename, Core::File::OpenMode::Read); + if (file_or_error.is_error()) { + auto error = DeprecatedString::formatted("'{}': {}", escape_token_for_single_quotes(filename), file_or_error.error()); if (explicitly_invoked) raise_error(ShellError::OpenFailure, error); else dbgln("open() failed for {}", error); return false; } - auto file = file_result.value(); - auto data = file->read_all(); - return run_command(data) == 0; + auto file = file_or_error.release_value(); + auto data_or_error = file->read_until_eof(); + if (data_or_error.is_error()) { + auto error = DeprecatedString::formatted("'{}': {}", escape_token_for_single_quotes(filename), data_or_error.error()); + if (explicitly_invoked) + raise_error(ShellError::OpenFailure, error); + else + dbgln("reading after open() failed for {}", error); + return false; + } + return run_command(data_or_error.value()) == 0; } bool Shell::is_allowed_to_modify_termios(const AST::Command& command) const diff --git a/Userland/Shell/main.cpp b/Userland/Shell/main.cpp index 7c2f52ae2e..6b0355164d 100644 --- a/Userland/Shell/main.cpp +++ b/Userland/Shell/main.cpp @@ -7,7 +7,6 @@ #include "Shell.h" #include <AK/LexicalPath.h> #include <LibCore/ArgsParser.h> -#include <LibCore/DeprecatedFile.h> #include <LibCore/Event.h> #include <LibCore/EventLoop.h> #include <LibCore/System.h> @@ -190,12 +189,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) skip_rc_files = true; if (!format.is_empty()) { - auto file = TRY(Core::DeprecatedFile::open(format, Core::OpenMode::ReadOnly)); + auto file = TRY(Core::File::open(format, Core::File::OpenMode::Read)); initialize(posix_mode); ssize_t cursor = -1; - puts(shell->format(file->read_all(), cursor).characters()); + puts(shell->format(TRY(file->read_until_eof()), cursor).characters()); return 0; } |