Checks presence of all blocks before deleting

This commit is contained in:
Ben 2024-05-22 09:47:48 +02:00
parent 5355c0c1f6
commit a3426a73f1
No known key found for this signature in database
GPG Key ID: 541B9D8C9F1426A1
1 changed files with 6 additions and 7 deletions

View File

@ -523,9 +523,6 @@ proc debugDelete*(self: CodexNodeRef, cid: Cid, blockIndices: seq[int]): Future[
totalBlocks = manifest.blocksCount
treeCid = manifest.treeCid
var
deleted = 0
for index in blockIndices:
if index >= totalBlocks:
return failure("Index out of range. Index: " & $index & " totalBlocks: " & $totalBlocks)
@ -533,10 +530,12 @@ proc debugDelete*(self: CodexNodeRef, cid: Cid, blockIndices: seq[int]): Future[
return failure(err)
if not hasBlock:
return failure("Tree does not have this index: " & $index & " totalBlocks: " & $totalBlocks)
else:
if err =? (await self.networkStore.delBlock(treeCid, index)).errorOption:
return failure(err)
inc deleted
var deleted = 0
for index in blockIndices:
if err =? (await self.networkStore.delBlock(treeCid, index)).errorOption:
return failure(err)
inc deleted
return success(deleted)