mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:17:34 +00:00
LibCore: Move Stream-based file into the Core
namespace
This commit is contained in:
parent
a96339b72b
commit
606a3982f3
218 changed files with 748 additions and 643 deletions
|
@ -21,6 +21,7 @@
|
|||
#include <LibAudio/FlacTypes.h>
|
||||
#include <LibAudio/LoaderError.h>
|
||||
#include <LibAudio/Resampler.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
|
||||
namespace Audio {
|
||||
|
@ -32,7 +33,7 @@ FlacLoaderPlugin::FlacLoaderPlugin(NonnullOwnPtr<SeekableStream> stream)
|
|||
|
||||
Result<NonnullOwnPtr<FlacLoaderPlugin>, LoaderError> FlacLoaderPlugin::create(StringView path)
|
||||
{
|
||||
auto stream = LOADER_TRY(Core::Stream::BufferedFile::create(LOADER_TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read))));
|
||||
auto stream = LOADER_TRY(Core::BufferedFile::create(LOADER_TRY(Core::File::open(path, Core::File::OpenMode::Read))));
|
||||
auto loader = make<FlacLoaderPlugin>(move(stream));
|
||||
|
||||
LOADER_TRY(loader->initialize());
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "MP3HuffmanTables.h"
|
||||
#include "MP3Tables.h"
|
||||
#include <AK/FixedArray.h>
|
||||
#include <LibCore/File.h>
|
||||
|
||||
namespace Audio {
|
||||
|
||||
|
@ -21,7 +22,7 @@ MP3LoaderPlugin::MP3LoaderPlugin(NonnullOwnPtr<SeekableStream> stream)
|
|||
|
||||
Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(StringView path)
|
||||
{
|
||||
auto stream = LOADER_TRY(Core::Stream::BufferedFile::create(LOADER_TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read))));
|
||||
auto stream = LOADER_TRY(Core::BufferedFile::create(LOADER_TRY(Core::File::open(path, Core::File::OpenMode::Read))));
|
||||
auto loader = make<MP3LoaderPlugin>(move(stream));
|
||||
|
||||
LOADER_TRY(loader->initialize());
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <AK/MemoryStream.h>
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <AK/Try.h>
|
||||
#include <LibCore/File.h>
|
||||
|
||||
namespace Audio {
|
||||
|
||||
|
@ -25,7 +26,7 @@ WavLoaderPlugin::WavLoaderPlugin(NonnullOwnPtr<SeekableStream> stream)
|
|||
|
||||
Result<NonnullOwnPtr<WavLoaderPlugin>, LoaderError> WavLoaderPlugin::create(StringView path)
|
||||
{
|
||||
auto stream = LOADER_TRY(Core::Stream::BufferedFile::create(LOADER_TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read))));
|
||||
auto stream = LOADER_TRY(Core::BufferedFile::create(LOADER_TRY(Core::File::open(path, Core::File::OpenMode::Read))));
|
||||
auto loader = make<WavLoaderPlugin>(move(stream));
|
||||
|
||||
LOADER_TRY(loader->initialize());
|
||||
|
|
|
@ -10,6 +10,7 @@ set(SOURCES
|
|||
ElapsedTimer.cpp
|
||||
Event.cpp
|
||||
EventLoop.cpp
|
||||
File.cpp
|
||||
IODevice.cpp
|
||||
LockFile.cpp
|
||||
MappedFile.cpp
|
||||
|
@ -25,7 +26,6 @@ set(SOURCES
|
|||
Socket.cpp
|
||||
SOCKSProxyClient.cpp
|
||||
StandardPaths.cpp
|
||||
Stream.cpp
|
||||
System.cpp
|
||||
SystemServerTakeover.cpp
|
||||
TCPServer.cpp
|
||||
|
|
|
@ -40,8 +40,8 @@ ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_system(DeprecatedString
|
|||
|
||||
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, AllowWriting allow_altering)
|
||||
{
|
||||
auto maybe_file = Stream::File::open(filename, allow_altering == AllowWriting::Yes ? Stream::OpenMode::ReadWrite : Stream::OpenMode::Read);
|
||||
OwnPtr<Stream::BufferedFile> buffered_file;
|
||||
auto maybe_file = File::open(filename, allow_altering == AllowWriting::Yes ? File::OpenMode::ReadWrite : File::OpenMode::Read);
|
||||
OwnPtr<BufferedFile> buffered_file;
|
||||
if (maybe_file.is_error()) {
|
||||
// If we attempted to open a read-only file that does not exist, we ignore the error, making it appear
|
||||
// the same as if we had opened an empty file. This behavior is a little weird, but is required by
|
||||
|
@ -49,7 +49,7 @@ ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& file
|
|||
if (!(allow_altering == AllowWriting::No && maybe_file.error().code() == ENOENT))
|
||||
return maybe_file.release_error();
|
||||
} else {
|
||||
buffered_file = TRY(Stream::BufferedFile::create(maybe_file.release_value()));
|
||||
buffered_file = TRY(BufferedFile::create(maybe_file.release_value()));
|
||||
}
|
||||
|
||||
auto config_file = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(filename, move(buffered_file))));
|
||||
|
@ -59,20 +59,20 @@ ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& file
|
|||
|
||||
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, int fd)
|
||||
{
|
||||
auto file = TRY(Stream::File::adopt_fd(fd, Stream::OpenMode::ReadWrite));
|
||||
auto file = TRY(File::adopt_fd(fd, File::OpenMode::ReadWrite));
|
||||
return open(filename, move(file));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, NonnullOwnPtr<Core::Stream::File> file)
|
||||
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, NonnullOwnPtr<Core::File> file)
|
||||
{
|
||||
auto buffered_file = TRY(Stream::BufferedFile::create(move(file)));
|
||||
auto buffered_file = TRY(BufferedFile::create(move(file)));
|
||||
|
||||
auto config_file = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(filename, move(buffered_file))));
|
||||
TRY(config_file->reparse());
|
||||
return config_file;
|
||||
}
|
||||
|
||||
ConfigFile::ConfigFile(DeprecatedString const& filename, OwnPtr<Stream::BufferedFile> open_file)
|
||||
ConfigFile::ConfigFile(DeprecatedString const& filename, OwnPtr<BufferedFile> open_file)
|
||||
: m_filename(filename)
|
||||
, m_file(move(open_file))
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
|
||||
namespace Core {
|
||||
|
@ -30,7 +31,7 @@ public:
|
|||
static ErrorOr<NonnullRefPtr<ConfigFile>> open_for_system(DeprecatedString const& app_name, AllowWriting = AllowWriting::No);
|
||||
static ErrorOr<NonnullRefPtr<ConfigFile>> open(DeprecatedString const& filename, AllowWriting = AllowWriting::No);
|
||||
static ErrorOr<NonnullRefPtr<ConfigFile>> open(DeprecatedString const& filename, int fd);
|
||||
static ErrorOr<NonnullRefPtr<ConfigFile>> open(DeprecatedString const& filename, NonnullOwnPtr<Core::Stream::File>);
|
||||
static ErrorOr<NonnullRefPtr<ConfigFile>> open(DeprecatedString const& filename, NonnullOwnPtr<Core::File>);
|
||||
~ConfigFile();
|
||||
|
||||
bool has_group(DeprecatedString const&) const;
|
||||
|
@ -78,12 +79,12 @@ public:
|
|||
DeprecatedString const& filename() const { return m_filename; }
|
||||
|
||||
private:
|
||||
ConfigFile(DeprecatedString const& filename, OwnPtr<Stream::BufferedFile> open_file);
|
||||
ConfigFile(DeprecatedString const& filename, OwnPtr<BufferedFile> open_file);
|
||||
|
||||
ErrorOr<void> reparse();
|
||||
|
||||
DeprecatedString m_filename;
|
||||
OwnPtr<Stream::BufferedFile> m_file;
|
||||
OwnPtr<BufferedFile> m_file;
|
||||
HashMap<DeprecatedString, HashMap<DeprecatedString, DeprecatedString>> m_groups;
|
||||
bool m_dirty { false };
|
||||
};
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Core {
|
|||
|
||||
///
|
||||
/// Use of Core::File for reading/writing data is deprecated.
|
||||
/// Please use Core::Stream::File and Core::Stream::BufferedFile instead.
|
||||
/// Please use Core::File and Core::BufferedFile instead.
|
||||
///
|
||||
class DeprecatedFile final : public IODevice {
|
||||
C_OBJECT(DeprecatedFile)
|
||||
|
|
|
@ -89,10 +89,10 @@ ErrorOr<LexicalPath> Directory::path() const
|
|||
return m_path.value();
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Stream::File>> Directory::open(StringView filename, Stream::OpenMode mode) const
|
||||
ErrorOr<NonnullOwnPtr<File>> Directory::open(StringView filename, File::OpenMode mode) const
|
||||
{
|
||||
auto fd = TRY(System::openat(m_directory_fd, filename, Stream::File::open_mode_to_options(mode)));
|
||||
return Stream::File::adopt_fd(fd, mode);
|
||||
auto fd = TRY(System::openat(m_directory_fd, filename, File::open_mode_to_options(mode)));
|
||||
return File::adopt_fd(fd, mode);
|
||||
}
|
||||
|
||||
ErrorOr<struct stat> Directory::stat() const
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <AK/LexicalPath.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -37,7 +38,7 @@ public:
|
|||
static ErrorOr<Directory> create(DeprecatedString path, CreateDirectories, mode_t creation_mode = 0755);
|
||||
static ErrorOr<Directory> adopt_fd(int fd, Optional<LexicalPath> path = {});
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Stream::File>> open(StringView filename, Stream::OpenMode mode) const;
|
||||
ErrorOr<NonnullOwnPtr<File>> open(StringView filename, File::OpenMode mode) const;
|
||||
ErrorOr<struct stat> stat() const;
|
||||
ErrorOr<DirIterator> create_iterator() const;
|
||||
|
||||
|
|
|
@ -5,22 +5,12 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "Stream.h"
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#ifdef AK_OS_SERENITY
|
||||
# include <serenity.h>
|
||||
#endif
|
||||
#ifdef AK_OS_FREEBSD
|
||||
# include <sys/ucred.h>
|
||||
#endif
|
||||
|
||||
namespace Core::Stream {
|
||||
namespace Core {
|
||||
|
||||
ErrorOr<NonnullOwnPtr<File>> File::open(StringView filename, OpenMode mode, mode_t permissions)
|
||||
{
|
||||
|
@ -36,7 +26,7 @@ ErrorOr<NonnullOwnPtr<File>> File::adopt_fd(int fd, OpenMode mode, ShouldCloseFi
|
|||
}
|
||||
|
||||
if (!has_any_flag(mode, OpenMode::ReadWrite)) {
|
||||
dbgln("Core::DeprecatedFile::adopt_fd: Attempting to adopt a file with neither Read nor Write specified in mode");
|
||||
dbgln("Core::File::adopt_fd: Attempting to adopt a file with neither Read nor Write specified in mode");
|
||||
return Error::from_errno(EINVAL);
|
||||
}
|
||||
|
108
Userland/Libraries/LibCore/File.h
Normal file
108
Userland/Libraries/LibCore/File.h
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/BufferedStream.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/Stream.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
class File final : public SeekableStream {
|
||||
AK_MAKE_NONCOPYABLE(File);
|
||||
|
||||
public:
|
||||
enum class OpenMode : unsigned {
|
||||
NotOpen = 0,
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
ReadWrite = 3,
|
||||
Append = 4,
|
||||
Truncate = 8,
|
||||
MustBeNew = 16,
|
||||
KeepOnExec = 32,
|
||||
Nonblocking = 64,
|
||||
};
|
||||
|
||||
enum class ShouldCloseFileDescriptor {
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
|
||||
static ErrorOr<NonnullOwnPtr<File>> open(StringView filename, OpenMode, mode_t = 0644);
|
||||
static ErrorOr<NonnullOwnPtr<File>> adopt_fd(int fd, OpenMode, ShouldCloseFileDescriptor = ShouldCloseFileDescriptor::Yes);
|
||||
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_input();
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_output();
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_error();
|
||||
static ErrorOr<NonnullOwnPtr<File>> open_file_or_standard_stream(StringView filename, OpenMode mode);
|
||||
|
||||
File(File&& other) { operator=(move(other)); }
|
||||
|
||||
File& operator=(File&& other)
|
||||
{
|
||||
if (&other == this)
|
||||
return *this;
|
||||
|
||||
m_mode = exchange(other.m_mode, OpenMode::NotOpen);
|
||||
m_fd = exchange(other.m_fd, -1);
|
||||
m_last_read_was_eof = exchange(other.m_last_read_was_eof, false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ErrorOr<Bytes> read(Bytes) override;
|
||||
virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096) override;
|
||||
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
|
||||
virtual bool is_eof() const override;
|
||||
virtual bool is_open() const override;
|
||||
virtual void close() override;
|
||||
virtual ErrorOr<size_t> seek(i64 offset, SeekMode) override;
|
||||
virtual ErrorOr<void> truncate(size_t length) override;
|
||||
|
||||
int leak_fd(Badge<::IPC::File>)
|
||||
{
|
||||
m_should_close_file_descriptor = ShouldCloseFileDescriptor::No;
|
||||
return m_fd;
|
||||
}
|
||||
|
||||
int fd() const
|
||||
{
|
||||
return m_fd;
|
||||
}
|
||||
|
||||
virtual ~File() override
|
||||
{
|
||||
if (m_should_close_file_descriptor == ShouldCloseFileDescriptor::Yes)
|
||||
close();
|
||||
}
|
||||
|
||||
static int open_mode_to_options(OpenMode mode);
|
||||
|
||||
private:
|
||||
File(OpenMode mode, ShouldCloseFileDescriptor should_close = ShouldCloseFileDescriptor::Yes)
|
||||
: m_mode(mode)
|
||||
, m_should_close_file_descriptor(should_close)
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<void> open_path(StringView filename, mode_t);
|
||||
|
||||
OpenMode m_mode { OpenMode::NotOpen };
|
||||
int m_fd { -1 };
|
||||
bool m_last_read_was_eof { false };
|
||||
ShouldCloseFileDescriptor m_should_close_file_descriptor { ShouldCloseFileDescriptor::Yes };
|
||||
};
|
||||
|
||||
AK_ENUM_BITWISE_OPERATORS(File::OpenMode)
|
||||
|
||||
using BufferedFile = BufferedSeekable<File>;
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ class DeferredInvocationContext;
|
|||
class ElapsedTimer;
|
||||
class Event;
|
||||
class EventLoop;
|
||||
class File;
|
||||
class IODevice;
|
||||
class LocalServer;
|
||||
class LocalSocket;
|
||||
|
@ -42,8 +43,4 @@ class UDPSocket;
|
|||
|
||||
enum class TimerShouldFireWhenNotVisible;
|
||||
|
||||
namespace Stream {
|
||||
class File;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/ProcessStatisticsReader.h>
|
||||
#include <pwd.h>
|
||||
|
||||
|
@ -90,7 +91,7 @@ ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(SeekableStream&
|
|||
|
||||
ErrorOr<AllProcessesStatistics> ProcessStatisticsReader::get_all(bool include_usernames)
|
||||
{
|
||||
auto proc_all_file = TRY(Core::Stream::File::open("/sys/kernel/processes"sv, Core::Stream::OpenMode::Read));
|
||||
auto proc_all_file = TRY(Core::File::open("/sys/kernel/processes"sv, Core::File::OpenMode::Read));
|
||||
return get_all(*proc_all_file, include_usernames);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,98 +25,3 @@
|
|||
#include <LibIPC/Forward.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
|
||||
namespace Core::Stream {
|
||||
|
||||
// Concrete classes.
|
||||
|
||||
enum class OpenMode : unsigned {
|
||||
NotOpen = 0,
|
||||
Read = 1,
|
||||
Write = 2,
|
||||
ReadWrite = 3,
|
||||
Append = 4,
|
||||
Truncate = 8,
|
||||
MustBeNew = 16,
|
||||
KeepOnExec = 32,
|
||||
Nonblocking = 64,
|
||||
};
|
||||
|
||||
enum class ShouldCloseFileDescriptor {
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
|
||||
AK_ENUM_BITWISE_OPERATORS(OpenMode)
|
||||
|
||||
class File final : public SeekableStream {
|
||||
AK_MAKE_NONCOPYABLE(File);
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullOwnPtr<File>> open(StringView filename, OpenMode, mode_t = 0644);
|
||||
static ErrorOr<NonnullOwnPtr<File>> adopt_fd(int fd, OpenMode, ShouldCloseFileDescriptor = ShouldCloseFileDescriptor::Yes);
|
||||
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_input();
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_output();
|
||||
static ErrorOr<NonnullOwnPtr<File>> standard_error();
|
||||
static ErrorOr<NonnullOwnPtr<File>> open_file_or_standard_stream(StringView filename, OpenMode mode);
|
||||
|
||||
File(File&& other) { operator=(move(other)); }
|
||||
|
||||
File& operator=(File&& other)
|
||||
{
|
||||
if (&other == this)
|
||||
return *this;
|
||||
|
||||
m_mode = exchange(other.m_mode, OpenMode::NotOpen);
|
||||
m_fd = exchange(other.m_fd, -1);
|
||||
m_last_read_was_eof = exchange(other.m_last_read_was_eof, false);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ErrorOr<Bytes> read(Bytes) override;
|
||||
virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096) override;
|
||||
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
|
||||
virtual bool is_eof() const override;
|
||||
virtual bool is_open() const override;
|
||||
virtual void close() override;
|
||||
virtual ErrorOr<size_t> seek(i64 offset, SeekMode) override;
|
||||
virtual ErrorOr<void> truncate(size_t length) override;
|
||||
|
||||
int leak_fd(Badge<::IPC::File>)
|
||||
{
|
||||
m_should_close_file_descriptor = ShouldCloseFileDescriptor::No;
|
||||
return m_fd;
|
||||
}
|
||||
|
||||
int fd() const
|
||||
{
|
||||
return m_fd;
|
||||
}
|
||||
|
||||
virtual ~File() override
|
||||
{
|
||||
if (m_should_close_file_descriptor == ShouldCloseFileDescriptor::Yes)
|
||||
close();
|
||||
}
|
||||
|
||||
static int open_mode_to_options(OpenMode mode);
|
||||
|
||||
private:
|
||||
File(OpenMode mode, ShouldCloseFileDescriptor should_close = ShouldCloseFileDescriptor::Yes)
|
||||
: m_mode(mode)
|
||||
, m_should_close_file_descriptor(should_close)
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<void> open_path(StringView filename, mode_t);
|
||||
|
||||
OpenMode m_mode { OpenMode::NotOpen };
|
||||
int m_fd { -1 };
|
||||
bool m_last_read_was_eof { false };
|
||||
ShouldCloseFileDescriptor m_should_close_file_descriptor { ShouldCloseFileDescriptor::Yes };
|
||||
};
|
||||
|
||||
using BufferedFile = BufferedSeekable<File>;
|
||||
|
||||
}
|
||||
|
|
|
@ -72,23 +72,23 @@ Result Client::request_file_read_only_approved(GUI::Window* parent_window, Depre
|
|||
return handle_promise<Result>(id);
|
||||
}
|
||||
|
||||
static Core::Stream::OpenMode to_stream_open_mode(Core::OpenMode open_mode)
|
||||
static Core::File::OpenMode to_stream_open_mode(Core::OpenMode open_mode)
|
||||
{
|
||||
Core::Stream::OpenMode result {};
|
||||
Core::File::OpenMode result {};
|
||||
if ((open_mode & Core::OpenMode::ReadOnly) == Core::OpenMode::ReadOnly)
|
||||
result |= Core::Stream::OpenMode::Read;
|
||||
result |= Core::File::OpenMode::Read;
|
||||
if ((open_mode & Core::OpenMode::WriteOnly) == Core::OpenMode::WriteOnly)
|
||||
result |= Core::Stream::OpenMode::Write;
|
||||
result |= Core::File::OpenMode::Write;
|
||||
if ((open_mode & Core::OpenMode::ReadWrite) == Core::OpenMode::ReadWrite)
|
||||
result |= Core::Stream::OpenMode::ReadWrite;
|
||||
result |= Core::File::OpenMode::ReadWrite;
|
||||
if ((open_mode & Core::OpenMode::Append) == Core::OpenMode::Append)
|
||||
result |= Core::Stream::OpenMode::Append;
|
||||
result |= Core::File::OpenMode::Append;
|
||||
if ((open_mode & Core::OpenMode::Truncate) == Core::OpenMode::Truncate)
|
||||
result |= Core::Stream::OpenMode::Truncate;
|
||||
result |= Core::File::OpenMode::Truncate;
|
||||
if ((open_mode & Core::OpenMode::MustBeNew) == Core::OpenMode::MustBeNew)
|
||||
result |= Core::Stream::OpenMode::MustBeNew;
|
||||
result |= Core::File::OpenMode::MustBeNew;
|
||||
if ((open_mode & Core::OpenMode::KeepOnExec) == Core::OpenMode::KeepOnExec)
|
||||
result |= Core::Stream::OpenMode::KeepOnExec;
|
||||
result |= Core::File::OpenMode::KeepOnExec;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ DeprecatedResult Client::try_request_file_deprecated(GUI::Window* parent_window,
|
|||
return handle_promise<DeprecatedResult>(id);
|
||||
}
|
||||
|
||||
Result Client::request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::Stream::OpenMode mode)
|
||||
Result Client::request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::File::OpenMode mode)
|
||||
{
|
||||
auto const id = get_new_id();
|
||||
m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
|
||||
|
@ -167,7 +167,7 @@ DeprecatedResult Client::try_open_file_deprecated(GUI::Window* parent_window, De
|
|||
return handle_promise<DeprecatedResult>(id);
|
||||
}
|
||||
|
||||
Result Client::open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::Stream::OpenMode requested_access)
|
||||
Result Client::open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::File::OpenMode requested_access)
|
||||
{
|
||||
auto const id = get_new_id();
|
||||
m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
|
||||
|
@ -209,7 +209,7 @@ DeprecatedResult Client::try_save_file_deprecated(GUI::Window* parent_window, De
|
|||
return handle_promise<DeprecatedResult>(id);
|
||||
}
|
||||
|
||||
Result Client::save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::Stream::OpenMode requested_access)
|
||||
Result Client::save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::File::OpenMode requested_access)
|
||||
{
|
||||
auto const id = get_new_id();
|
||||
m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
|
||||
|
@ -275,7 +275,7 @@ void Client::handle_prompt_end(i32 request_id, i32 error, Optional<IPC::File> co
|
|||
}
|
||||
|
||||
auto file_or_error = [&]() -> ErrorOr<File> {
|
||||
auto stream = TRY(Core::Stream::File::adopt_fd(ipc_file->take_fd(), Core::Stream::OpenMode::ReadWrite));
|
||||
auto stream = TRY(Core::File::adopt_fd(ipc_file->take_fd(), Core::File::OpenMode::ReadWrite));
|
||||
auto filename = TRY(String::from_deprecated_string(*chosen_file));
|
||||
return File({}, move(stream), filename);
|
||||
}();
|
||||
|
|
|
@ -22,18 +22,18 @@ namespace FileSystemAccessClient {
|
|||
class Client;
|
||||
class File {
|
||||
public:
|
||||
File(Badge<Client>, NonnullOwnPtr<Core::Stream::File> stream, String filename)
|
||||
File(Badge<Client>, NonnullOwnPtr<Core::File> stream, String filename)
|
||||
: m_stream(move(stream))
|
||||
, m_filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
Core::Stream::File& stream() const { return *m_stream; }
|
||||
NonnullOwnPtr<Core::Stream::File> release_stream() { return move(m_stream); }
|
||||
Core::File& stream() const { return *m_stream; }
|
||||
NonnullOwnPtr<Core::File> release_stream() { return move(m_stream); }
|
||||
String filename() const { return m_filename; }
|
||||
|
||||
private:
|
||||
NonnullOwnPtr<Core::Stream::File> m_stream;
|
||||
NonnullOwnPtr<Core::File> m_stream;
|
||||
String m_filename;
|
||||
};
|
||||
|
||||
|
@ -52,9 +52,9 @@ public:
|
|||
DeprecatedResult try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
|
||||
|
||||
Result request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path);
|
||||
Result request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::Stream::OpenMode requested_access);
|
||||
Result open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::Stream::OpenMode requested_access = Core::Stream::OpenMode::Read);
|
||||
Result save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::Stream::OpenMode requested_access = Core::Stream::OpenMode::Write | Core::Stream::OpenMode::Truncate);
|
||||
Result request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::File::OpenMode requested_access);
|
||||
Result open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::File::OpenMode requested_access = Core::File::OpenMode::Read);
|
||||
Result save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::File::OpenMode requested_access = Core::File::OpenMode::Write | Core::File::OpenMode::Truncate);
|
||||
|
||||
static Client& the();
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ void AbstractThemePreview::set_theme(Core::AnonymousBuffer const& theme_buffer)
|
|||
set_preview_palette(m_preview_palette);
|
||||
}
|
||||
|
||||
ErrorOr<void> AbstractThemePreview::set_theme_from_file(StringView path, NonnullOwnPtr<Core::Stream::File> file)
|
||||
ErrorOr<void> AbstractThemePreview::set_theme_from_file(StringView path, NonnullOwnPtr<Core::File> file)
|
||||
{
|
||||
auto config_file = TRY(Core::ConfigFile::open(path, move(file)));
|
||||
auto theme = TRY(Gfx::load_system_theme(config_file));
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
|
||||
Gfx::Palette const& preview_palette() const { return m_preview_palette; }
|
||||
void set_preview_palette(Gfx::Palette const&);
|
||||
ErrorOr<void> set_theme_from_file(StringView path, NonnullOwnPtr<Core::Stream::File>);
|
||||
ErrorOr<void> set_theme_from_file(StringView path, NonnullOwnPtr<Core::File>);
|
||||
void set_theme(Core::AnonymousBuffer const&);
|
||||
|
||||
void paint_window(StringView title, Gfx::IntRect const& rect, Gfx::WindowTheme::WindowState, Gfx::Bitmap const& icon, int button_count = 3);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/JsonObject.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/StandardPaths.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibGUI/CommonLocationsProvider.h>
|
||||
|
@ -42,7 +43,7 @@ static void initialize_if_needed()
|
|||
|
||||
ErrorOr<void> CommonLocationsProvider::load_from_json(StringView json_path)
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open(json_path, Core::Stream::OpenMode::Read));
|
||||
auto file = TRY(Core::File::open(json_path, Core::File::OpenMode::Read));
|
||||
auto json = JsonValue::from_string(TRY(file->read_until_eof()));
|
||||
if (json.is_error())
|
||||
return Error::from_string_literal("File is not a valid JSON");
|
||||
|
|
|
@ -1460,12 +1460,12 @@ void TextEditor::timer_event(Core::TimerEvent&)
|
|||
|
||||
ErrorOr<void> TextEditor::write_to_file(StringView path)
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Write | Core::Stream::OpenMode::Truncate));
|
||||
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Write | Core::File::OpenMode::Truncate));
|
||||
TRY(write_to_file(*file));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> TextEditor::write_to_file(Core::Stream::File& file)
|
||||
ErrorOr<void> TextEditor::write_to_file(Core::File& file)
|
||||
{
|
||||
off_t file_size = 0;
|
||||
if (line_count() == 1 && line(0).is_empty()) {
|
||||
|
|
|
@ -130,7 +130,7 @@ public:
|
|||
void insert_at_cursor_or_replace_selection(StringView);
|
||||
void replace_all_text_without_resetting_undo_stack(StringView text);
|
||||
ErrorOr<void> write_to_file(StringView path);
|
||||
ErrorOr<void> write_to_file(Core::Stream::File&);
|
||||
ErrorOr<void> write_to_file(Core::File&);
|
||||
bool has_selection() const { return m_selection.is_valid(); }
|
||||
DeprecatedString selected_text() const;
|
||||
size_t number_of_words() const;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/BuiltinWrappers.h>
|
||||
#include <AK/Utf32View.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibGfx/Font/FontDatabase.h>
|
||||
#include <LibGfx/Font/FontStyleMapping.h>
|
||||
|
@ -257,7 +258,7 @@ ErrorOr<void> BitmapFont::write_to_file(DeprecatedString const& path)
|
|||
memcpy(header.name, m_name.characters(), min(m_name.length(), sizeof(header.name) - 1));
|
||||
memcpy(header.family, m_family.characters(), min(m_family.length(), sizeof(header.family) - 1));
|
||||
|
||||
auto stream = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Write));
|
||||
auto stream = TRY(Core::File::open(path, Core::File::OpenMode::Write));
|
||||
size_t bytes_per_glyph = sizeof(u32) * m_glyph_height;
|
||||
TRY(stream->write_entire_buffer({ &header, sizeof(header) }));
|
||||
TRY(stream->write_entire_buffer({ m_range_mask, m_range_mask_size }));
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <AK/LexicalPath.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibCore/DeprecatedFile.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
|
||||
[[noreturn]] static void report_parsing_error(StringView message, StringView filename, StringView input, size_t offset)
|
||||
|
@ -149,7 +150,7 @@ Optional<Interface&> Parser::resolve_import(auto path)
|
|||
report_parsing_error(DeprecatedString::formatted("Circular import detected: {}", include_path), filename, input, lexer.tell());
|
||||
import_stack.set(real_path);
|
||||
|
||||
auto file_or_error = Core::Stream::File::open(real_path, Core::Stream::OpenMode::Read);
|
||||
auto file_or_error = Core::File::open(real_path, Core::File::OpenMode::Read);
|
||||
if (file_or_error.is_error())
|
||||
report_parsing_error(DeprecatedString::formatted("Failed to open {}: {}", real_path, file_or_error.error()), filename, input, lexer.tell());
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -41,7 +42,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename... Args>
|
||||
File(Core::Stream::File& file, Args... args)
|
||||
File(Core::File& file, Args... args)
|
||||
: File(file.leak_fd(Badge<File> {}), args...)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -602,7 +602,7 @@ ErrorOr<void> Editor::interrupted()
|
|||
|
||||
m_finish = false;
|
||||
{
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
TRY(reposition_cursor(*stderr_stream, true));
|
||||
if (TRY(m_suggestion_display->cleanup()))
|
||||
TRY(reposition_cursor(*stderr_stream, true));
|
||||
|
@ -648,7 +648,7 @@ ErrorOr<void> Editor::handle_resize_event(bool reset_origin)
|
|||
|
||||
set_origin(m_origin_row, 1);
|
||||
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
|
||||
TRY(reposition_cursor(*stderr_stream, true));
|
||||
TRY(m_suggestion_display->redisplay(m_suggestion_manager, m_num_lines, m_num_columns));
|
||||
|
@ -665,7 +665,7 @@ ErrorOr<void> Editor::really_quit_event_loop()
|
|||
{
|
||||
m_finish = false;
|
||||
{
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
TRY(reposition_cursor(*stderr_stream, true));
|
||||
TRY(stderr_stream->write_entire_buffer("\n"sv.bytes()));
|
||||
}
|
||||
|
@ -731,7 +731,7 @@ auto Editor::get_line(DeprecatedString const& prompt) -> Result<DeprecatedString
|
|||
strip_styles(true);
|
||||
|
||||
{
|
||||
auto stderr_stream = Core::Stream::File::standard_error().release_value_but_fixme_should_propagate_errors();
|
||||
auto stderr_stream = Core::File::standard_error().release_value_but_fixme_should_propagate_errors();
|
||||
auto prompt_lines = max(current_prompt_metrics().line_metrics.size(), 1ul) - 1;
|
||||
for (size_t i = 0; i < prompt_lines; ++i)
|
||||
stderr_stream->write_entire_buffer("\n"sv.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||
|
@ -1173,7 +1173,7 @@ ErrorOr<void> Editor::handle_read_event()
|
|||
for (auto& view : completion_result.insert)
|
||||
insert(view);
|
||||
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
TRY(reposition_cursor(*stderr_stream));
|
||||
|
||||
if (completion_result.style_to_apply.has_value()) {
|
||||
|
@ -1252,7 +1252,7 @@ ErrorOr<void> Editor::cleanup_suggestions()
|
|||
// We probably have some suggestions drawn,
|
||||
// let's clean them up.
|
||||
if (TRY(m_suggestion_display->cleanup())) {
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
TRY(reposition_cursor(*stderr_stream));
|
||||
m_refresh_needed = true;
|
||||
}
|
||||
|
@ -1326,7 +1326,7 @@ ErrorOr<void> Editor::cleanup()
|
|||
if (new_lines < m_shown_lines)
|
||||
m_extra_forward_lines = max(m_shown_lines - new_lines, m_extra_forward_lines);
|
||||
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
TRY(reposition_cursor(*stderr_stream, true));
|
||||
auto current_line = num_lines() - 1;
|
||||
TRY(VT::clear_lines(current_line, m_extra_forward_lines, *stderr_stream));
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/ScopedValueRollback.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/TemporaryChange.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibLine/Editor.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/wait.h>
|
||||
|
@ -341,7 +342,7 @@ void Editor::enter_search()
|
|||
auto& search_string = search_string_result.value();
|
||||
|
||||
// Manually cleanup the search line.
|
||||
auto stderr_stream = Core::Stream::File::standard_error().release_value_but_fixme_should_propagate_errors();
|
||||
auto stderr_stream = Core::File::standard_error().release_value_but_fixme_should_propagate_errors();
|
||||
reposition_cursor(*stderr_stream).release_value_but_fixme_should_propagate_errors();
|
||||
auto search_metrics = actual_rendered_string_metrics(search_string, {});
|
||||
auto metrics = actual_rendered_string_metrics(search_prompt, {});
|
||||
|
@ -433,7 +434,7 @@ void Editor::go_end()
|
|||
void Editor::clear_screen()
|
||||
{
|
||||
warn("\033[3J\033[H\033[2J");
|
||||
auto stream = Core::Stream::File::standard_error().release_value_but_fixme_should_propagate_errors();
|
||||
auto stream = Core::File::standard_error().release_value_but_fixme_should_propagate_errors();
|
||||
VT::move_absolute(1, 1, *stream).release_value_but_fixme_should_propagate_errors();
|
||||
set_origin(1, 1);
|
||||
m_refresh_needed = true;
|
||||
|
@ -528,7 +529,7 @@ void Editor::edit_in_external_editor()
|
|||
|
||||
{
|
||||
auto write_fd = dup(fd);
|
||||
auto stream = Core::Stream::File::adopt_fd(write_fd, Core::Stream::OpenMode::Write).release_value_but_fixme_should_propagate_errors();
|
||||
auto stream = Core::File::adopt_fd(write_fd, Core::File::OpenMode::Write).release_value_but_fixme_should_propagate_errors();
|
||||
StringBuilder builder;
|
||||
builder.append(Utf32View { m_buffer.data(), m_buffer.size() });
|
||||
auto bytes = builder.string_view().bytes();
|
||||
|
@ -569,7 +570,7 @@ void Editor::edit_in_external_editor()
|
|||
}
|
||||
|
||||
{
|
||||
auto file = Core::Stream::File::open({ file_path, strlen(file_path) }, Core::Stream::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
|
||||
auto file = Core::File::open({ file_path, strlen(file_path) }, Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
|
||||
auto contents = file->read_until_eof().release_value_but_fixme_should_propagate_errors();
|
||||
StringView data { contents };
|
||||
while (data.ends_with('\n'))
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <AK/BinarySearch.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibLine/SuggestionDisplay.h>
|
||||
#include <LibLine/VT.h>
|
||||
#include <stdio.h>
|
||||
|
@ -17,7 +18,7 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
|
|||
{
|
||||
did_display();
|
||||
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
|
||||
size_t longest_suggestion_length = 0;
|
||||
size_t longest_suggestion_byte_length = 0;
|
||||
|
@ -161,7 +162,7 @@ ErrorOr<bool> XtermSuggestionDisplay::cleanup()
|
|||
did_cleanup();
|
||||
|
||||
if (m_lines_used_for_last_suggestions) {
|
||||
auto stderr_stream = TRY(Core::Stream::File::standard_error());
|
||||
auto stderr_stream = TRY(Core::File::standard_error());
|
||||
TRY(VT::clear_lines(0, m_lines_used_for_last_suggestions, *stderr_stream));
|
||||
m_lines_used_for_last_suggestions = 0;
|
||||
return true;
|
||||
|
|
|
@ -24,7 +24,7 @@ void Request::stream_into(AK::Stream& stream)
|
|||
{
|
||||
VERIFY(!m_internal_stream_data);
|
||||
|
||||
m_internal_stream_data = make<InternalStreamData>(MUST(Core::Stream::File::adopt_fd(fd(), Core::Stream::OpenMode::Read)));
|
||||
m_internal_stream_data = make<InternalStreamData>(MUST(Core::File::adopt_fd(fd(), Core::File::OpenMode::Read)));
|
||||
m_internal_stream_data->read_notifier = Core::Notifier::construct(fd(), Core::Notifier::Read);
|
||||
|
||||
auto user_on_finish = move(on_finish);
|
||||
|
|
|
@ -47,8 +47,8 @@ ErrorOr<void> Heap::open()
|
|||
if (file_size > 0)
|
||||
m_next_block = m_end_of_file = file_size / BLOCKSIZE;
|
||||
|
||||
auto file = TRY(Core::Stream::File::open(name(), Core::Stream::OpenMode::ReadWrite));
|
||||
m_file = TRY(Core::Stream::BufferedFile::create(move(file)));
|
||||
auto file = TRY(Core::File::open(name(), Core::File::OpenMode::ReadWrite));
|
||||
m_file = TRY(Core::BufferedFile::create(move(file)));
|
||||
|
||||
if (file_size > 0) {
|
||||
if (auto error_maybe = read_zero_block(); error_maybe.is_error()) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibCore/Stream.h>
|
||||
|
||||
|
@ -99,7 +100,7 @@ private:
|
|||
void initialize_zero_block();
|
||||
void update_zero_block();
|
||||
|
||||
OwnPtr<Core::Stream::BufferedFile> m_file;
|
||||
OwnPtr<Core::BufferedFile> m_file;
|
||||
u32 m_free_list { 0 };
|
||||
u32 m_next_block { 1 };
|
||||
u32 m_end_of_file { 1 };
|
||||
|
|
|
@ -67,7 +67,7 @@ static ErrorOr<void> launch_server(DeprecatedString const& socket_path, Deprecat
|
|||
server_pid = TRY(Core::System::fork());
|
||||
|
||||
if (server_pid != 0) {
|
||||
auto server_pid_file = TRY(Core::Stream::File::open(pid_path, Core::Stream::OpenMode::Write));
|
||||
auto server_pid_file = TRY(Core::File::open(pid_path, Core::File::OpenMode::Write));
|
||||
TRY(server_pid_file->write(DeprecatedString::number(server_pid).bytes()));
|
||||
|
||||
TRY(Core::System::kill(getpid(), SIGTERM));
|
||||
|
@ -108,7 +108,7 @@ static ErrorOr<bool> should_launch_server(DeprecatedString const& pid_path)
|
|||
|
||||
Optional<pid_t> pid;
|
||||
{
|
||||
auto server_pid_file = Core::Stream::File::open(pid_path, Core::Stream::OpenMode::Read);
|
||||
auto server_pid_file = Core::File::open(pid_path, Core::File::OpenMode::Read);
|
||||
if (server_pid_file.is_error()) {
|
||||
warnln("Could not open SQLServer PID file '{}': {}", pid_path, server_pid_file.error());
|
||||
return server_pid_file.release_error();
|
||||
|
|
|
@ -140,7 +140,7 @@ bool TLSv12::compute_master_secret_from_pre_master_secret(size_t length)
|
|||
}
|
||||
|
||||
if constexpr (TLS_SSL_KEYLOG_DEBUG) {
|
||||
auto file = MUST(Core::Stream::File::open("/home/anon/ssl_keylog"sv, Core::Stream::OpenMode::Append | Core::Stream::OpenMode::Write));
|
||||
auto file = MUST(Core::File::open("/home/anon/ssl_keylog"sv, Core::File::OpenMode::Append | Core::File::OpenMode::Write));
|
||||
MUST(file->write_entire_buffer("CLIENT_RANDOM "sv.bytes()));
|
||||
MUST(file->write_entire_buffer(encode_hex({ m_context.local_random, 32 }).bytes()));
|
||||
MUST(file->write_entire_buffer(" "sv.bytes()));
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <AK/Result.h>
|
||||
#include <AK/Tuple.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
|
@ -217,7 +218,7 @@ inline JS::ThrowCompletionOr<void> TestRunnerGlobalObject::initialize(JS::Realm&
|
|||
inline ByteBuffer load_entire_file(StringView path)
|
||||
{
|
||||
auto try_load_entire_file = [](StringView const& path) -> ErrorOr<ByteBuffer> {
|
||||
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_size = TRY(file->size());
|
||||
auto content = TRY(ByteBuffer::create_uninitialized(file_size));
|
||||
TRY(file->read(content.bytes()));
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <Kernel/API/VirGL.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibVirtGPU/CommandBufferBuilder.h>
|
||||
#include <LibVirtGPU/Device.h>
|
||||
|
@ -38,14 +39,14 @@ static constexpr auto vert_shader = "VERT\n"
|
|||
" 4: MOV_SAT OUT[1], IN[1]\n"
|
||||
" 5: END\n"sv;
|
||||
|
||||
Device::Device(NonnullOwnPtr<Core::Stream::File> gpu_file)
|
||||
Device::Device(NonnullOwnPtr<Core::File> gpu_file)
|
||||
: m_gpu_file { move(gpu_file) }
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Device>> Device::create(Gfx::IntSize min_size)
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open("/dev/gpu/render0"sv, Core::Stream::OpenMode::ReadWrite));
|
||||
auto file = TRY(Core::File::open("/dev/gpu/render0"sv, Core::File::OpenMode::ReadWrite));
|
||||
auto device = make<Device>(move(file));
|
||||
TRY(device->initialize_context(min_size));
|
||||
return device;
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace VirtGPU {
|
|||
|
||||
class Device final : public GPU::Device {
|
||||
public:
|
||||
Device(NonnullOwnPtr<Core::Stream::File>);
|
||||
Device(NonnullOwnPtr<Core::File>);
|
||||
|
||||
static ErrorOr<NonnullOwnPtr<Device>> create(Gfx::IntSize min_size);
|
||||
|
||||
|
@ -66,7 +66,7 @@ private:
|
|||
ErrorOr<Protocol::ResourceID> create_virgl_resource(VirGL3DResourceSpec&);
|
||||
ErrorOr<void> upload_command_buffer(Vector<u32> const&);
|
||||
|
||||
NonnullOwnPtr<Core::Stream::File> m_gpu_file;
|
||||
NonnullOwnPtr<Core::File> m_gpu_file;
|
||||
|
||||
Protocol::ResourceID m_vbo_resource_id { 0 };
|
||||
Protocol::ResourceID m_drawtarget { 0 };
|
||||
|
|
|
@ -250,7 +250,7 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, Has
|
|||
|
||||
auto const fd = file_or_error.value();
|
||||
|
||||
auto maybe_file = Core::Stream::File::adopt_fd(fd, Core::Stream::OpenMode::Read);
|
||||
auto maybe_file = Core::File::adopt_fd(fd, Core::File::OpenMode::Read);
|
||||
if (maybe_file.is_error()) {
|
||||
log_failure(request, maybe_file.error());
|
||||
if (error_callback)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue