Fix paths :o

This commit is contained in:
Alex 2020-04-17 19:20:17 +02:00
parent 4abfb75509
commit b4e96bdcf0

View file

@ -76,8 +76,7 @@ impl BlockManager {
} }
pub async fn read_block(&self, hash: &Hash) -> Result<Message, Error> { pub async fn read_block(&self, hash: &Hash) -> Result<Message, Error> {
let mut path = self.block_dir(hash); let path = self.block_path(hash);
path.push(hex::encode(hash));
let mut f = match fs::File::open(&path).await { let mut f = match fs::File::open(&path).await {
Ok(f) => f, Ok(f) => f,
@ -112,8 +111,7 @@ impl BlockManager {
.map(|x| u64_from_bytes(x.as_ref()) > 0) .map(|x| u64_from_bytes(x.as_ref()) > 0)
.unwrap_or(false); .unwrap_or(false);
if needed { if needed {
let mut path = self.data_dir.clone(); let path = self.block_path(hash);
path.push(hex::encode(hash.as_ref()));
let exists = fs::metadata(&path).await.is_ok(); let exists = fs::metadata(&path).await.is_ok();
Ok(!exists) Ok(!exists)
} else { } else {
@ -127,6 +125,11 @@ impl BlockManager {
path.push(hex::encode(&hash.as_slice()[1..2])); path.push(hex::encode(&hash.as_slice()[1..2]));
path path
} }
fn block_path(&self, hash: &Hash) -> PathBuf {
let mut path = self.block_dir(hash);
path.push(hex::encode(hash.as_ref()));
path
}
pub fn block_incref(&self, hash: &Hash) -> Result<(), Error> { pub fn block_incref(&self, hash: &Hash) -> Result<(), Error> {
let new_rc = self.rc.merge(&hash, vec![1])?; let new_rc = self.rc.merge(&hash, vec![1])?;
@ -187,8 +190,7 @@ impl BlockManager {
} }
async fn resync_iter(&self, hash: &Hash) -> Result<(), Error> { async fn resync_iter(&self, hash: &Hash) -> Result<(), Error> {
let mut path = self.data_dir.clone(); let path = self.block_path(hash);
path.push(hex::encode(hash.as_ref()));
let exists = fs::metadata(&path).await.is_ok(); let exists = fs::metadata(&path).await.is_ok();
let needed = self let needed = self