1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:37:34 +00:00

LibCore+Everywhere: Move OpenMode out of IODevice

...and make it an enum class so people don't omit "OpenMode".
This commit is contained in:
Ali Mohammad Pur 2021-05-12 13:56:43 +04:30 committed by Linus Groh
parent 422ef7904e
commit a91a49337c
113 changed files with 180 additions and 177 deletions

View file

@ -170,7 +170,7 @@ void Editor::show_documentation_tooltip_if_available(const String& hovered_token
dbgln_if(EDITOR_DEBUG, "opening {}", it->value);
auto file = Core::File::construct(it->value);
if (!file->open(Core::File::ReadOnly)) {
if (!file->open(Core::OpenMode::ReadOnly)) {
dbgln("failed to open {}, {}", it->value, file->error_string());
return;
}

View file

@ -149,7 +149,7 @@ void GitWidget::show_diff(const LexicalPath& file_path)
{
if (!m_git_repo->is_tracked(file_path)) {
auto file = Core::File::construct(file_path.string());
if (!file->open(Core::IODevice::ReadOnly)) {
if (!file->open(Core::OpenMode::ReadOnly)) {
perror("open");
VERIFY_NOT_REACHED();
}

View file

@ -340,7 +340,7 @@ NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_file_action()
filepath = String::formatted("{}{}", filepath, filename);
auto file = Core::File::construct(filepath);
if (!file->open((Core::IODevice::OpenMode)(Core::IODevice::WriteOnly | Core::IODevice::MustBeNew))) {
if (!file->open((Core::OpenMode)(Core::OpenMode::WriteOnly | Core::OpenMode::MustBeNew))) {
GUI::MessageBox::show(window(), String::formatted("Failed to create '{}'", filepath), "Error", GUI::MessageBox::Type::Error);
return;
}

View file

@ -73,7 +73,7 @@ String FileDB::to_absolute_path(const String& filename) const
RefPtr<GUI::TextDocument> FileDB::create_from_filesystem(const String& filename) const
{
auto file = Core::File::open(to_absolute_path(filename), Core::IODevice::ReadOnly);
auto file = Core::File::open(to_absolute_path(filename), Core::OpenMode::ReadOnly);
if (file.is_error()) {
dbgln("failed to create document for {} from filesystem", filename);
return nullptr;
@ -84,7 +84,7 @@ RefPtr<GUI::TextDocument> FileDB::create_from_filesystem(const String& filename)
RefPtr<GUI::TextDocument> FileDB::create_from_fd(int fd) const
{
auto file = Core::File::construct();
if (!file->open(fd, Core::IODevice::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes)) {
if (!file->open(fd, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes)) {
errno = file->error();
perror("open");
dbgln("Failed to open project file");

View file

@ -55,7 +55,7 @@ void ProjectFile::create_document_if_needed() const
return;
m_document = CodeDocument::create(m_name);
auto file_or_error = Core::File::open(m_name, Core::File::ReadOnly);
auto file_or_error = Core::File::open(m_name, Core::OpenMode::ReadOnly);
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

@ -90,7 +90,7 @@ int main(int argc, char** argv)
}
auto file = Core::File::construct(argv[1]);
if (!file->open(Core::IODevice::ReadOnly)) {
if (!file->open(Core::OpenMode::ReadOnly)) {
warnln("Error: Cannot open {}: {}", argv[1], file->error_string());
return 1;
}

View file

@ -115,7 +115,7 @@ int main(int argc, char** argv)
editor.set_cursor(4, 28); // after "...widgets!"
} else {
auto file = Core::File::construct(path);
if (!file->open(Core::IODevice::ReadOnly)) {
if (!file->open(Core::OpenMode::ReadOnly)) {
GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error);
return 1;
}
@ -143,7 +143,7 @@ int main(int argc, char** argv)
return;
auto file = Core::File::construct(open_path.value());
if (!file->open(Core::IODevice::ReadOnly) && file->error() != ENOENT) {
if (!file->open(Core::OpenMode::ReadOnly) && file->error() != ENOENT) {
GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", open_path.value(), strerror(errno)), "Error", GUI::MessageBox::Type::Error);
return;
}

View file

@ -192,7 +192,7 @@ void Profile::rebuild_tree()
Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const StringView& path)
{
auto file = Core::File::construct(path);
if (!file->open(Core::IODevice::ReadOnly))
if (!file->open(Core::OpenMode::ReadOnly))
return String::formatted("Unable to open {}, error: {}", path, file->error_string());
auto json = JsonValue::from_string(file->read_all());