aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-17 19:20:17 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-17 19:20:17 +0200
commitb4e96bdcf0b8c74595ae9156d200504f502a96f1 (patch)
treed95d3d2a38bc21bcc468297ebe439720422727fb
parent4abfb75509f216f4d62bc8b18b22eb680eefe2d9 (diff)
downloadgarage-b4e96bdcf0b8c74595ae9156d200504f502a96f1.tar.gz
garage-b4e96bdcf0b8c74595ae9156d200504f502a96f1.zip
Fix paths :o
-rw-r--r--src/block.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/block.rs b/src/block.rs
index cd570bda..ff38d65c 100644
--- a/src/block.rs
+++ b/src/block.rs
@@ -76,8 +76,7 @@ impl BlockManager {
}
pub async fn read_block(&self, hash: &Hash) -> Result<Message, Error> {
- let mut path = self.block_dir(hash);
- path.push(hex::encode(hash));
+ let path = self.block_path(hash);
let mut f = match fs::File::open(&path).await {
Ok(f) => f,
@@ -112,8 +111,7 @@ impl BlockManager {
.map(|x| u64_from_bytes(x.as_ref()) > 0)
.unwrap_or(false);
if needed {
- let mut path = self.data_dir.clone();
- path.push(hex::encode(hash.as_ref()));
+ let path = self.block_path(hash);
let exists = fs::metadata(&path).await.is_ok();
Ok(!exists)
} else {
@@ -127,6 +125,11 @@ impl BlockManager {
path.push(hex::encode(&hash.as_slice()[1..2]));
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> {
let new_rc = self.rc.merge(&hash, vec![1])?;
@@ -187,8 +190,7 @@ impl BlockManager {
}
async fn resync_iter(&self, hash: &Hash) -> Result<(), Error> {
- let mut path = self.data_dir.clone();
- path.push(hex::encode(hash.as_ref()));
+ let path = self.block_path(hash);
let exists = fs::metadata(&path).await.is_ok();
let needed = self