mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-03-02 02:13:07 +00:00
Prevent further underflow when deleting blocks
This commit is contained in:
parent
4c3cfabe6c
commit
8e337478f2
@ -157,7 +157,7 @@ proc updateBlockMetadata*(
|
||||
BlockMetadata(
|
||||
size: currBlockMd.size,
|
||||
expiry: max(currBlockMd.expiry, minExpiry),
|
||||
refCount: currBlockMd.refCount + plusRefCount - minusRefCount,
|
||||
refCount: max(0, currBlockMd.refCount + plusRefCount - minusRefCount),
|
||||
).some
|
||||
else:
|
||||
raise newException(
|
||||
|
||||
@ -272,7 +272,8 @@ method delBlock*(
|
||||
error "Failed to delete leaf metadata, block will remain on disk.", err = err.msg
|
||||
return failure(err)
|
||||
|
||||
if err =?
|
||||
if leafMd.blkCid.mcodec == BlockCodec and
|
||||
err =?
|
||||
(await self.updateBlockMetadata(leafMd.blkCid, minusRefCount = 1)).errorOption:
|
||||
if not (err of BlockNotFoundError):
|
||||
return failure(err)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user