graph: force unlink graph in case major failure (ref #704)

This commit is contained in:
jeefo 2025-08-09 20:25:13 +03:00
commit 97945966cd
No known key found for this signature in database
GPG key ID: D696786B81B667C8

View file

@ -92,12 +92,21 @@ template <typename U> bool BotStorage::load (SmallArray <U> &data, ExtenHeader *
return false;
}
// erase the current graph just in case
auto unlinkIfGraph = [&] () {
if (isGraph) {
unlinkFromDisk (false);
}
};
// read the header
StorageHeader hdr {};
file.read (&hdr, sizeof (StorageHeader));
// check the magic
if (hdr.magic != kStorageMagic && hdr.magic != kStorageMagicUB) {
unlinkIfGraph ();
if (tryReload ()) {
return true;
}
@ -111,6 +120,8 @@ template <typename U> bool BotStorage::load (SmallArray <U> &data, ExtenHeader *
// check the count
if (hdr.length == 0 || hdr.length > kMaxNodes || hdr.length < kMaxNodeLinks) {
unlinkIfGraph ();
if (tryReload ()) {
return true;
}