1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 07:24:58 +00:00

AK: Make MappedFile heap-allocated and ref-counted

Let's adapt this class a bit better to how it's actually being used.

Instead of having valid/invalid states and storing an error in case
it's invalid, a MappedFile is now always valid, and the factory
function that creates it will return an OSError if mapping fails.
This commit is contained in:
Andreas Kling 2021-01-10 15:55:54 +01:00
parent 70fce5c4c7
commit 2f3b901f7f
36 changed files with 184 additions and 199 deletions

View file

@ -150,12 +150,14 @@ Icon FileIconProvider::icon_for_executable(const String& path)
// If the icon for an app isn't in the cache we attempt to load the file as an ELF image and extract
// the serenity_app_icon_* sections which should contain the icons as raw PNG data. In the future it would
// be better if the binary signalled the image format being used or we deduced it, e.g. using magic bytes.
auto mapped_file = make<MappedFile>(path);
if (!mapped_file->is_valid()) {
auto file_or_error = MappedFile::map(path);
if (file_or_error.is_error()) {
app_icon_cache.set(path, s_executable_icon);
return s_executable_icon;
}
auto& mapped_file = file_or_error.value();
if (mapped_file->size() < SELFMAG) {
app_icon_cache.set(path, s_executable_icon);
return s_executable_icon;