Skip to content

Commit

Permalink
read file instead of check its existence
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Sep 22, 2024
1 parent a54f850 commit c7c02f7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions rfs/src/store/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@ impl Store for DirStore {
let file_name = hex::encode(key);
let dir_path = self.root.join(&file_name[0..2]);

let path = match fs::try_exists(&dir_path).await {
Ok(true) => dir_path.join(file_name),
Ok(false) => self.root.join(file_name),
Err(e) => return Err(Error::IO(e)),
};

let mut path = dir_path.join(&file_name);
let data = match fs::read(&path).await {
Ok(data) => data,
Err(err) if err.kind() == ErrorKind::NotFound => {
return Err(Error::KeyNotFound);
path = self.root.join(file_name);
let data = match fs::read(&path).await {
Ok(data) => data,
Err(err) if err.kind() == ErrorKind::NotFound => {
return Err(Error::KeyNotFound);
}
Err(err) => {
return Err(Error::IO(err));
}
};
data
}
Err(err) => {
return Err(Error::IO(err));
Expand Down

0 comments on commit c7c02f7

Please sign in to comment.