fs: handle filesystem_error in directory_archive::load()

we were hitting this on CI when attempting to load a texture called
"light"; file_size() was throwing because it was attempting to
get the file size of a directory called "light".
This commit is contained in:
Eric Wasylishen 2023-01-29 18:56:24 -07:00
parent 23e98c0e94
commit 837524999b
1 changed files with 10 additions and 5 deletions

View File

@ -48,11 +48,16 @@ struct directory_archive : archive_like
return std::nullopt;
}
uintmax_t size = file_size(p);
std::ifstream stream(p, std::ios_base::in | std::ios_base::binary);
std::vector<uint8_t> data(size);
stream.read(reinterpret_cast<char *>(data.data()), size);
return data;
try {
uintmax_t size = file_size(p);
std::ifstream stream(p, std::ios_base::in | std::ios_base::binary);
std::vector<uint8_t> data(size);
stream.read(reinterpret_cast<char *>(data.data()), size);
return data;
} catch (const filesystem_error &e) {
logging::funcprint("WARNING: {}\n", e.what());
return std::nullopt;
}
}
};