removeBlock method
- String cid
Returns a Future that resolves to a RemoveBlockResponse after removing the block with the given cid.
Implementation
@override
/// Returns a [Future] that resolves to a [RemoveBlockResponse] after removing the block with the given [cid].
Future<RemoveBlockResponse> removeBlock(String cid) async {
try {
final blockPath = p.join(path, cid);
final fileExists = await getPlatform().exists(blockPath);
final indexed = _blockIndex.contains(cid);
if (!fileExists && !indexed) {
_logger.debug('Block not found for removal: $cid');
return BlockResponseFactory.failureRemove('Block not found: $cid');
}
if (fileExists) {
_totalSize -= await getPlatform().getLength(blockPath);
await getPlatform().delete(blockPath);
} else {
_totalSize -= _blockCache.get(cid)?.size ?? 0;
}
_blockIndex.remove(cid);
_blockCache.remove(cid);
_logger.debug('Block removed successfully: $cid');
return BlockResponseFactory.successRemove('Block removed successfully');
} catch (e) {
_logger.error('Failed to remove block $cid', e);
return BlockResponseFactory.failureRemove('Failed to remove block: $e');
}
}