delete old block when receiving a compressed one
This commit is contained in:
parent
f802148395
commit
a51f671d86
1 changed files with 14 additions and 6 deletions
|
@ -764,15 +764,21 @@ impl BlockManagerLocked {
|
||||||
fs::create_dir_all(&path).await?;
|
fs::create_dir_all(&path).await?;
|
||||||
|
|
||||||
path.push(hex::encode(hash));
|
path.push(hex::encode(hash));
|
||||||
match mgr.is_block_compressed(hash).await {
|
let to_delete = match (mgr.is_block_compressed(hash).await, compressed) {
|
||||||
Ok(true) => return Ok(BlockRpc::Ok),
|
(Ok(true), _) => return Ok(BlockRpc::Ok),
|
||||||
Ok(false) if !compressed => return Ok(BlockRpc::Ok),
|
(Ok(false), false) => return Ok(BlockRpc::Ok),
|
||||||
_ => {
|
(Ok(false), true) => {
|
||||||
|
let path_to_delete = path.clone();
|
||||||
|
path.set_extension("zst");
|
||||||
|
Some(path_to_delete)
|
||||||
|
}
|
||||||
|
(Err(_), compressed) => {
|
||||||
if compressed {
|
if compressed {
|
||||||
path.set_extension("zst");
|
path.set_extension("zst");
|
||||||
}
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let mut path2 = path.clone();
|
let mut path2 = path.clone();
|
||||||
path2.set_extension("tmp");
|
path2.set_extension("tmp");
|
||||||
|
@ -781,6 +787,9 @@ impl BlockManagerLocked {
|
||||||
drop(f);
|
drop(f);
|
||||||
|
|
||||||
fs::rename(path2, path).await?;
|
fs::rename(path2, path).await?;
|
||||||
|
if let Some(to_delete) = to_delete {
|
||||||
|
fs::remove_file(to_delete).await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(BlockRpc::Ok)
|
Ok(BlockRpc::Ok)
|
||||||
}
|
}
|
||||||
|
@ -793,7 +802,6 @@ impl BlockManagerLocked {
|
||||||
let mut path = mgr.block_path(hash);
|
let mut path = mgr.block_path(hash);
|
||||||
let mut path2 = path.clone();
|
let mut path2 = path.clone();
|
||||||
if mgr.is_block_compressed(hash).await? {
|
if mgr.is_block_compressed(hash).await? {
|
||||||
// block marked as corrupted, and absent? That should not happen
|
|
||||||
path.set_extension("zst");
|
path.set_extension("zst");
|
||||||
path2.set_extension("zst.corrupted");
|
path2.set_extension("zst.corrupted");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue