Resync block on read error

This commit is contained in:
Alex 2020-04-17 18:38:11 +02:00
parent b780f6485d
commit 4bacaaf53f

View file

@ -77,7 +77,14 @@ impl BlockManager {
let mut path = self.block_dir(hash); let mut path = self.block_dir(hash);
path.push(hex::encode(hash)); path.push(hex::encode(hash));
let mut f = fs::File::open(&path).await?; let mut f = match fs::File::open(&path).await {
Ok(f) => f,
Err(e) => {
// Not found but maybe we should have had it ??
self.put_to_resync(hash, DEFAULT_TIMEOUT.as_millis() as u64)?;
return Err(Into::into(e));
}
};
let mut data = vec![]; let mut data = vec![];
f.read_to_end(&mut data).await?; f.read_to_end(&mut data).await?;
drop(f); drop(f);