graph: force unlink graph in case major failure (ref #704)
This commit is contained in:
parent
6da92fe0f2
commit
97945966cd
1 changed files with 11 additions and 0 deletions
|
|
@ -92,12 +92,21 @@ template <typename U> bool BotStorage::load (SmallArray <U> &data, ExtenHeader *
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// erase the current graph just in case
|
||||||
|
auto unlinkIfGraph = [&] () {
|
||||||
|
if (isGraph) {
|
||||||
|
unlinkFromDisk (false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// read the header
|
// read the header
|
||||||
StorageHeader hdr {};
|
StorageHeader hdr {};
|
||||||
file.read (&hdr, sizeof (StorageHeader));
|
file.read (&hdr, sizeof (StorageHeader));
|
||||||
|
|
||||||
// check the magic
|
// check the magic
|
||||||
if (hdr.magic != kStorageMagic && hdr.magic != kStorageMagicUB) {
|
if (hdr.magic != kStorageMagic && hdr.magic != kStorageMagicUB) {
|
||||||
|
unlinkIfGraph ();
|
||||||
|
|
||||||
if (tryReload ()) {
|
if (tryReload ()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -111,6 +120,8 @@ template <typename U> bool BotStorage::load (SmallArray <U> &data, ExtenHeader *
|
||||||
|
|
||||||
// check the count
|
// check the count
|
||||||
if (hdr.length == 0 || hdr.length > kMaxNodes || hdr.length < kMaxNodeLinks) {
|
if (hdr.length == 0 || hdr.length > kMaxNodes || hdr.length < kMaxNodeLinks) {
|
||||||
|
unlinkIfGraph ();
|
||||||
|
|
||||||
if (tryReload ()) {
|
if (tryReload ()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue