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

Everywhere: Remove unintentional partial stream reads and writes

This commit is contained in:
Tim Schumacher 2023-03-01 17:24:50 +01:00 committed by Linus Groh
parent 26516ee160
commit ae51c1821c
44 changed files with 109 additions and 192 deletions

View file

@ -775,8 +775,7 @@ ErrorOr<void> BrowserWindow::take_screenshot(ScreenshotType type)
auto encoded = TRY(Gfx::PNGWriter::encode(*bitmap.bitmap()));
auto screenshot_file = TRY(Core::File::open(path.string(), Core::File::OpenMode::Write));
// FIXME: This should write the entire span.
TRY(screenshot_file->write_some(encoded));
TRY(screenshot_file->write_until_depleted(encoded));
return {};
}

View file

@ -50,8 +50,7 @@ ErrorOr<void> DomainListModel::save()
TRY(builder.try_appendff("{}\n", domain));
auto file = TRY(Core::File::open(filter_list_file_path(), Core::File::OpenMode::Write));
// FIXME: This should write the entire span.
TRY(file->write_some(TRY(builder.to_byte_buffer()).bytes()));
TRY(file->write_until_depleted(TRY(builder.to_byte_buffer()).bytes()));
return {};
}

View file

@ -284,8 +284,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
auto byte_buffer = byte_buffer_or_error.release_value();
// FIXME: This should write the entire span.
if (auto result = file->write_some(byte_buffer); result.is_error())
if (auto result = file->write_until_depleted(byte_buffer); result.is_error())
GUI::MessageBox::show(window, DeprecatedString::formatted("Couldn't save file: {}.", result.release_error()), "Saving backtrace failed"sv, GUI::MessageBox::Type::Error);
};
save_backtrace_button.set_enabled(false);

View file

@ -62,12 +62,10 @@ void HexDocumentMemory::clear_changes()
ErrorOr<void> HexDocumentMemory::write_to_file(Core::File& file)
{
TRY(file.seek(0, SeekMode::SetPosition));
// FIXME: This should write the entire span.
TRY(file.write_some(m_buffer));
TRY(file.write_until_depleted(m_buffer));
for (auto& change : m_changes) {
TRY(file.seek(change.key, SeekMode::SetPosition));
// FIXME: This should write the entire span.
TRY(file.write_some({ &change.value, 1 }));
TRY(file.write_until_depleted({ &change.value, 1 }));
}
return {};
}
@ -89,8 +87,7 @@ ErrorOr<void> HexDocumentFile::write_to_file()
{
for (auto& change : m_changes) {
TRY(m_file->seek(change.key, SeekMode::SetPosition));
// FIXME: This should write the entire span.
TRY(m_file->write_some({ &change.value, 1 }));
TRY(m_file->write_until_depleted({ &change.value, 1 }));
}
clear_changes();
// make sure the next get operation triggers a read
@ -110,14 +107,12 @@ ErrorOr<void> HexDocumentFile::write_to_file(Core::File& file)
auto copy_buffer = TRY(m_file->read_some(buffer));
if (copy_buffer.size() == 0)
break;
// FIXME: This should write the entire span.
TRY(file.write_some(copy_buffer));
TRY(file.write_until_depleted(copy_buffer));
}
for (auto& change : m_changes) {
TRY(file.seek(change.key, SeekMode::SetPosition));
// FIXME: This should write the entire span.
TRY(file.write_some({ &change.value, 1 }));
TRY(file.write_until_depleted({ &change.value, 1 }));
}
return {};

View file

@ -191,8 +191,7 @@ ErrorOr<void> KeyboardMapperWidget::save_to_file(StringView filename)
// Write to file.
DeprecatedString file_content = map_json.to_deprecated_string();
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Write));
// FIXME: This should write the entire span.
TRY(file->write_some(file_content.bytes()));
TRY(file->write_until_depleted(file_content.bytes()));
file->close();
window()->set_modified(false);

View file

@ -73,8 +73,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
filename = path.basename();
auto encoded = TRY(dump_bitmap(magnifier->current_bitmap(), path.extension()));
// FIXME: This should write the entire span.
TRY(file->write_some(encoded));
TRY(file->write_until_depleted(encoded));
return {};
};

View file

@ -187,8 +187,7 @@ ErrorOr<void> RunWindow::save_history()
// Write the first 25 items of history
for (int i = 0; i < min(static_cast<int>(m_path_history.size()), 25); i++)
// FIXME: This should write the entire span.
TRY(file->write_some(DeprecatedString::formatted("{}\n", m_path_history[i]).bytes()));
TRY(file->write_until_depleted(DeprecatedString::formatted("{}\n", m_path_history[i]).bytes()));
return {};
}