1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 01:17:46 +00:00

LibCore: Move Stream-based file into the Core namespace

This commit is contained in:
Tim Schumacher 2023-02-09 03:02:46 +01:00 committed by Linus Groh
parent a96339b72b
commit 606a3982f3
218 changed files with 748 additions and 643 deletions

View file

@ -157,7 +157,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
save_as_action->activate();
return;
}
auto response = FileSystemAccessClient::Client::the().request_file(window, file_path, Core::Stream::OpenMode::Truncate | Core::Stream::OpenMode::Write);
auto response = FileSystemAccessClient::Client::the().request_file(window, file_path, Core::File::OpenMode::Truncate | Core::File::OpenMode::Write);
if (response.is_error())
return;

View file

@ -232,7 +232,7 @@ void Editor::show_documentation_tooltip_if_available(DeprecatedString const& hov
}
dbgln_if(EDITOR_DEBUG, "opening {}", it->value);
auto file_or_error = Core::Stream::File::open(it->value, Core::Stream::OpenMode::Read);
auto file_or_error = Core::File::open(it->value, Core::File::OpenMode::Read);
if (file_or_error.is_error()) {
dbgln("Failed to open {}, {}", it->value, file_or_error.error());
return;

View file

@ -155,7 +155,7 @@ void GitWidget::set_view_diff_callback(ViewDiffCallback callback)
void GitWidget::show_diff(DeprecatedString const& file_path)
{
if (!m_git_repo->is_tracked(file_path)) {
auto file = Core::Stream::File::open(file_path, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
auto file = Core::File::open(file_path, Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
auto content = file->read_until_eof().release_value_but_fixme_should_propagate_errors();
m_view_diff_callback("", Diff::generate_only_additions(content));
return;

View file

@ -550,7 +550,7 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_new_file_action(Dep
filepath = DeprecatedString::formatted("{}{}", filepath, filename);
auto file_or_error = Core::Stream::File::open(filepath, Core::Stream::OpenMode::Write | Core::Stream::OpenMode::MustBeNew);
auto file_or_error = Core::File::open(filepath, Core::File::OpenMode::Write | Core::File::OpenMode::MustBeNew);
if (file_or_error.is_error()) {
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to create '{}': {}", filepath, file_or_error.error()));
return;
@ -1791,7 +1791,7 @@ ErrorOr<NonnullRefPtr<GUI::Action>> HackStudioWidget::create_open_project_config
if (maybe_error.is_error() && maybe_error.error().code() != EEXIST)
return maybe_error.release_error();
auto file = TRY(Core::Stream::File::open(absolute_config_file_path, Core::Stream::OpenMode::Write));
auto file = TRY(Core::File::open(absolute_config_file_path, Core::File::OpenMode::Write));
TRY(file->write_entire_buffer(
"{\n"
" \"build_command\": \"your build command here\",\n"

View file

@ -9,6 +9,7 @@
#include <AK/Debug.h>
#include <AK/LexicalPath.h>
#include <AK/NonnullRefPtr.h>
#include <LibCore/File.h>
namespace LanguageServers {
@ -74,13 +75,13 @@ DeprecatedString FileDB::to_absolute_path(DeprecatedString const& filename) cons
ErrorOr<NonnullRefPtr<GUI::TextDocument>> FileDB::create_from_filesystem(DeprecatedString const& filename) const
{
auto file = TRY(Core::Stream::File::open(to_absolute_path(filename), Core::Stream::OpenMode::Read));
auto file = TRY(Core::File::open(to_absolute_path(filename), Core::File::OpenMode::Read));
return create_from_file(move(file));
}
ErrorOr<NonnullRefPtr<GUI::TextDocument>> FileDB::create_from_fd(int fd) const
{
auto file = TRY(Core::Stream::File::adopt_fd(fd, Core::Stream::OpenMode::Read));
auto file = TRY(Core::File::adopt_fd(fd, Core::File::OpenMode::Read));
return create_from_file(move(file));
}
@ -101,7 +102,7 @@ public:
};
static DefaultDocumentClient s_default_document_client;
ErrorOr<NonnullRefPtr<GUI::TextDocument>> FileDB::create_from_file(NonnullOwnPtr<Core::Stream::File> file) const
ErrorOr<NonnullRefPtr<GUI::TextDocument>> FileDB::create_from_file(NonnullOwnPtr<Core::File> file) const
{
auto content = TRY(file->read_until_eof());
auto document = GUI::TextDocument::create(&s_default_document_client);

View file

@ -34,7 +34,7 @@ public:
private:
ErrorOr<NonnullRefPtr<GUI::TextDocument>> create_from_filesystem(DeprecatedString const& filename) const;
ErrorOr<NonnullRefPtr<GUI::TextDocument>> create_from_fd(int fd) const;
ErrorOr<NonnullRefPtr<GUI::TextDocument>> create_from_file(NonnullOwnPtr<Core::Stream::File>) const;
ErrorOr<NonnullRefPtr<GUI::TextDocument>> create_from_file(NonnullOwnPtr<Core::File>) const;
static RefPtr<GUI::TextDocument> create_with_content(DeprecatedString const&);
private:

View file

@ -112,7 +112,7 @@ ErrorOr<void> ProjectBuilder::build_serenity_component()
ErrorOr<DeprecatedString> ProjectBuilder::component_name(StringView cmake_file_path)
{
auto file = TRY(Core::Stream::File::open(cmake_file_path, Core::Stream::OpenMode::Read));
auto file = TRY(Core::File::open(cmake_file_path, Core::File::OpenMode::Read));
auto content = TRY(file->read_until_eof());
static Regex<ECMA262> const component_name(R"~~~(serenity_component\([\s]*(\w+)[\s\S]*\))~~~");
@ -135,7 +135,7 @@ ErrorOr<void> ProjectBuilder::initialize_build_directory()
if (Core::DeprecatedFile::exists(cmake_file_path))
MUST(Core::DeprecatedFile::remove(cmake_file_path, Core::DeprecatedFile::RecursionMode::Disallowed));
auto cmake_file = TRY(Core::Stream::File::open(cmake_file_path, Core::Stream::OpenMode::Write));
auto cmake_file = TRY(Core::File::open(cmake_file_path, Core::File::OpenMode::Write));
TRY(cmake_file->write_entire_buffer(generate_cmake_file_content().bytes()));
TRY(m_terminal->run_command(DeprecatedString::formatted("cmake -S {} -DHACKSTUDIO_BUILD=ON -DHACKSTUDIO_BUILD_CMAKE_FILE={}"

View file

@ -6,6 +6,7 @@
#include "ProjectConfig.h"
#include <AK/NonnullOwnPtr.h>
#include <LibCore/File.h>
#include <LibCore/Stream.h>
namespace HackStudio {
@ -17,7 +18,7 @@ ProjectConfig::ProjectConfig(JsonObject config)
ErrorOr<NonnullOwnPtr<ProjectConfig>> ProjectConfig::try_load_project_config(DeprecatedString path)
{
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
auto file_contents = TRY(file->read_until_eof());
auto json = TRY(JsonValue::from_string(file_contents));

View file

@ -5,6 +5,7 @@
*/
#include "ProjectFile.h"
#include <LibCore/File.h>
#include <LibCore/Stream.h>
namespace HackStudio {
@ -54,7 +55,7 @@ void ProjectFile::create_document_if_needed() const
return;
m_document = CodeDocument::create(m_name);
auto file_or_error = Core::Stream::File::open(m_name, Core::Stream::OpenMode::Read);
auto file_or_error = Core::File::open(m_name, Core::File::OpenMode::Read);
if (file_or_error.is_error()) {
warnln("Couldn't open '{}': {}", m_name, file_or_error.error());
// This is okay though, we'll just go with an empty document and create the file when saving.

View file

@ -236,7 +236,7 @@ OwnPtr<Debug::DebugInfo> g_kernel_debug_info;
ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path)
{
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
auto json = JsonValue::from_string(TRY(file->read_until_eof()));
if (json.is_error() || !json.value().is_object())

View file

@ -29,8 +29,8 @@ public:
DeprecatedString source_file_name = filename.replace("../../"sv, source_root_path, ReplaceMode::FirstOnly);
auto try_read_lines = [&]() -> ErrorOr<void> {
auto unbuffered_file = TRY(Core::Stream::File::open(source_file_name, Core::Stream::OpenMode::Read));
auto file = TRY(Core::Stream::BufferedFile::create(move(unbuffered_file)));
auto unbuffered_file = TRY(Core::File::open(source_file_name, Core::File::OpenMode::Read));
auto file = TRY(Core::BufferedFile::create(move(unbuffered_file)));
Array<u8, 1024> buffer;
while (!file->is_eof())

View file

@ -29,7 +29,7 @@ void ScriptEditor::new_script_with_temp_name(DeprecatedString name)
ErrorOr<void> ScriptEditor::open_script_from_file(LexicalPath const& file_path)
{
auto file = TRY(Core::Stream::File::open(file_path.string(), Core::Stream::OpenMode::Read));
auto file = TRY(Core::File::open(file_path.string(), Core::File::OpenMode::Read));
auto buffer = TRY(file->read_until_eof());
set_text({ buffer.bytes() });
@ -40,7 +40,7 @@ ErrorOr<void> ScriptEditor::open_script_from_file(LexicalPath const& file_path)
static ErrorOr<void> save_text_to_file(StringView filename, DeprecatedString text)
{
auto file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Write));
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Write));
if (!text.is_empty())
TRY(file->write_entire_buffer(text.bytes()));

View file

@ -61,7 +61,7 @@ int main(int argc, char** argv, char** env)
OwnPtr<Vector<int>> profile_string_id_map;
if (dump_profile) {
auto profile_stream_or_error = Core::Stream::File::open(profile_dump_path, Core::Stream::OpenMode::Write);
auto profile_stream_or_error = Core::File::open(profile_dump_path, Core::File::OpenMode::Write);
if (profile_stream_or_error.is_error()) {
warnln("Failed to open '{}' for writing: {}", profile_dump_path, profile_stream_or_error.error());
return 1;