From 97945966cd8cb4ed83dc223b4c595d20ecc962e5 Mon Sep 17 00:00:00 2001 From: jeefo Date: Sat, 9 Aug 2025 20:25:13 +0300 Subject: [PATCH] graph: force unlink graph in case major failure (ref #704) --- src/storage.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/storage.cpp b/src/storage.cpp index 50ccdc7..4d341c1 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -92,12 +92,21 @@ template bool BotStorage::load (SmallArray &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 bool BotStorage::load (SmallArray &data, ExtenHeader * // check the count if (hdr.length == 0 || hdr.length > kMaxNodes || hdr.length < kMaxNodeLinks) { + unlinkIfGraph (); + if (tryReload ()) { return true; }