1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:47:34 +00:00

AK: Add the Input word to input-only buffered streams

This concerns both `BufferedSeekable` and `BufferedFile`.
This commit is contained in:
Lucas CHOLLET 2023-05-03 18:45:18 -04:00 committed by Andreas Kling
parent 48b000a36c
commit 8c34959b53
50 changed files with 101 additions and 102 deletions

View file

@ -41,7 +41,7 @@ ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open_for_system(DeprecatedString
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, AllowWriting allow_altering)
{
auto maybe_file = File::open(filename, allow_altering == AllowWriting::Yes ? File::OpenMode::ReadWrite : File::OpenMode::Read);
OwnPtr<BufferedFile> buffered_file;
OwnPtr<InputBufferedFile> 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(BufferedFile::create(maybe_file.release_value()));
buffered_file = TRY(InputBufferedFile::create(maybe_file.release_value()));
}
auto config_file = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ConfigFile(filename, move(buffered_file))));
@ -65,14 +65,14 @@ ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& file
ErrorOr<NonnullRefPtr<ConfigFile>> ConfigFile::open(DeprecatedString const& filename, NonnullOwnPtr<Core::File> file)
{
auto buffered_file = TRY(BufferedFile::create(move(file)));
auto buffered_file = TRY(InputBufferedFile::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<BufferedFile> open_file)
ConfigFile::ConfigFile(DeprecatedString const& filename, OwnPtr<InputBufferedFile> open_file)
: m_filename(filename)
, m_file(move(open_file))
{

View file

@ -79,12 +79,12 @@ public:
DeprecatedString const& filename() const { return m_filename; }
private:
ConfigFile(DeprecatedString const& filename, OwnPtr<BufferedFile> open_file);
ConfigFile(DeprecatedString const& filename, OwnPtr<InputBufferedFile> open_file);
ErrorOr<void> reparse();
DeprecatedString m_filename;
OwnPtr<BufferedFile> m_file;
OwnPtr<InputBufferedFile> m_file;
HashMap<DeprecatedString, HashMap<DeprecatedString, DeprecatedString>> m_groups;
bool m_dirty { false };
};

View file

@ -19,7 +19,7 @@ namespace Core {
///
/// Use of Core::File for reading/writing data is deprecated.
/// Please use Core::File and Core::BufferedFile instead.
/// Please use Core::File and Core::InputBufferedFile instead.
///
class DeprecatedFile final : public IODevice {
C_OBJECT(DeprecatedFile)

View file

@ -105,6 +105,6 @@ private:
AK_ENUM_BITWISE_OPERATORS(File::OpenMode)
using BufferedFile = BufferedSeekable<File>;
using InputBufferedFile = InputBufferedSeekable<File>;
}