Skip to content

Commit

Permalink
Fix linux access
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdy committed Jul 6, 2023
1 parent f64c601 commit cc203d8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 40 deletions.
4 changes: 3 additions & 1 deletion zerostash-files/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ fn tree_get(c: &mut Criterion) {
let mut tree = Tree::default();
fill_tree(&mut tree, 50, 1_000, 10);
let path = get_path("1", 1_000);
c.bench_function("tree get 50,1000,10", |b| b.iter(|| tree.get(&path)));
c.bench_function("tree get 50,1000,10", |b| {
b.iter(|| tree.node_by_path(&path))
});
}

fn tree_remove(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion zerostash-files/src/stash/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async fn process_file_loop(

if !force {
let tree = &index.tree;
if let Ok(Some(node)) = tree.get(&path_str) {
if let Ok(Some(node)) = tree.node_by_path(&path_str) {
match node.as_ref() {
crate::Node::File { refs: _, entry: e } if *e.as_ref() == entry => {
debug!(?path, "already indexed, skipping");
Expand Down
52 changes: 22 additions & 30 deletions zerostash-files/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Tree {
}

/// Return a file
pub fn get_file<'a>(&self, path: &'a str) -> Result<'a, Option<Arc<Entry>>> {
pub fn file<'a>(&self, path: &'a str) -> Result<'a, Option<Arc<Entry>>> {
let Some(noderef) = self.get_ref(path)? else {
return Ok(None);
};
Expand All @@ -180,8 +180,12 @@ impl Tree {
Ok(node.as_file())
}

pub fn node_by_ref(&self, noderef: &Digest) -> Option<Arc<Node>> {
self.0.get(noderef)
}

/// Return a file system node
pub fn get<'a>(&self, path: &'a str) -> Result<'a, Option<Arc<Node>>> {
pub fn node_by_path<'a>(&self, path: &'a str) -> Result<'a, Option<Arc<Node>>> {
if path == "/" {
return Ok(Some(self.root()));
}
Expand Down Expand Up @@ -546,11 +550,11 @@ mod test {
let res = tree.insert_file(file_path, Entry::default());
assert!(res.is_ok());

let res = tree.get_file(file_path);
let res = tree.file(file_path);
assert!(res.is_ok() && res.unwrap().is_some());

assert!(tree.remove(file_path).is_ok());
assert!(tree.get_file(file_path).unwrap().is_none());
assert!(tree.file(file_path).unwrap().is_none());
}

#[test]
Expand Down Expand Up @@ -578,14 +582,10 @@ mod test {
_ = tree_index.insert_file(&random_file, Entry::default());

_ = tree_index.move_node(&file_path, &new_file_path);
assert!(tree_index.get_file(&file_path).unwrap().is_none());
assert!(tree_index.file(&file_path).unwrap().is_none());

assert_eq!(
tree_index
.get_file(&new_file_path)
.unwrap()
.unwrap()
.as_ref(),
tree_index.file(&new_file_path).unwrap().unwrap().as_ref(),
&entry
);
}
Expand All @@ -597,13 +597,9 @@ mod test {
{
let tree_index = &tree.index().tree;

assert!(tree_index.get_file(&file_path).unwrap().is_none());
assert!(tree_index.file(&file_path).unwrap().is_none());
assert_eq!(
tree_index
.get_file(&new_file_path)
.unwrap()
.unwrap()
.as_ref(),
tree_index.file(&new_file_path).unwrap().unwrap().as_ref(),
&entry
);
}
Expand All @@ -616,13 +612,9 @@ mod test {
tree.load_all().unwrap();
let tree_index = &tree.index().tree;

assert!(tree_index.get_file(&file_path).unwrap().is_none());
assert!(tree_index.file(&file_path).unwrap().is_none());
assert_eq!(
tree_index
.get_file(&new_file_path)
.unwrap()
.unwrap()
.as_ref(),
tree_index.file(&new_file_path).unwrap().unwrap().as_ref(),
&entry
);
}
Expand Down Expand Up @@ -702,7 +694,7 @@ mod test {
.is_err());

tree_index.insert_file(&file_path, entry).unwrap();
let entry_name = &tree_index.get_file(&file_path).unwrap().unwrap().name;
let entry_name = &tree_index.file(&file_path).unwrap().unwrap().name;

assert_eq!(entry_name, "file.rs");
}
Expand All @@ -714,11 +706,11 @@ mod test {
{
let tree_index = &tree.index().tree;

let entry_name = &tree_index.get_file(&file_path).unwrap().unwrap().name;
let entry_name = &tree_index.file(&file_path).unwrap().unwrap().name;
assert_eq!(entry_name, "file.rs");

let _ = tree_index.update_file(&file_path, new_entry);
let entry_name = &tree_index.get_file(&file_path).unwrap().unwrap().name;
let entry_name = &tree_index.file(&file_path).unwrap().unwrap().name;
assert_eq!(entry_name, "new_file.rs");
}

Expand All @@ -729,7 +721,7 @@ mod test {

tree.load_all().unwrap();
let tree_index = &tree.index().tree;
let entry_name = &tree_index.get_file(&file_path).unwrap().unwrap().name;
let entry_name = &tree_index.file(&file_path).unwrap().unwrap().name;

assert_eq!(entry_name, "new_file.rs");
}
Expand Down Expand Up @@ -774,7 +766,7 @@ mod test {
.unwrap();

assert_eq!(
&tree.index().tree.get_file(&file1).unwrap().unwrap().name,
&tree.index().tree.file(&file1).unwrap().unwrap().name,
"file1.rs"
);
index.insert_file(&file3, Entry::default()).unwrap();
Expand All @@ -787,7 +779,7 @@ mod test {
tree.load_all().unwrap();

assert_eq!(
&tree.index().tree.get_file(&file1).unwrap().unwrap().name,
&tree.index().tree.file(&file1).unwrap().unwrap().name,
"file1.rs"
);

Expand Down Expand Up @@ -843,7 +835,7 @@ mod test {
let file = "test/path/to/file.rs".to_string();
tree.insert_file(&file, Entry::default()).unwrap();

let node = tree.get("test/path/to").unwrap().unwrap();
let node = tree.node_by_path("test/path/to").unwrap().unwrap();
assert!(node.is_dir());
}

Expand Down Expand Up @@ -882,6 +874,6 @@ mod test {

assert!(tree.remove("home/travel").is_ok());

assert!(tree.get("home/travel").unwrap().is_none());
assert!(tree.node_by_path("home/travel").unwrap().is_none());
}
}
16 changes: 8 additions & 8 deletions zerostash-fuse/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl FilesystemMT for ZerostashFS {
let stash = self.stash.lock().unwrap();
let index = &stash.index();
let tree = &index.tree;
tree.get(path_str)
tree.node_by_path(path_str)
};

let Ok(Some(node)) = node else {
Expand All @@ -172,7 +172,7 @@ impl FilesystemMT for ZerostashFS {
let stash = self.stash.lock().unwrap();
let index = stash.index();
let tree = &index.tree;
tree.get(path_str)
tree.node_by_path(path_str)
};

let Ok(Some(node)) = node else {
Expand All @@ -188,7 +188,7 @@ impl FilesystemMT for ZerostashFS {

let mut vec: Vec<DirectoryEntry> = vec![];
entries.for_each(|k, v| {
if let Some(node) = index.tree.0.get(v) {
if let Some(node) = index.tree.node_by_ref(v) {
let kind = if node.is_dir() {
fuse_mt::FileType::Directory
} else {
Expand Down Expand Up @@ -228,7 +228,7 @@ impl FilesystemMT for ZerostashFS {
let stash = self.stash.lock().unwrap();
let index = &stash.index();
let tree = &index.tree;
let Ok(Some(entry)) = tree.get_file(path_string) else {
let Ok(Some(entry)) = tree.file(path_string) else {
return callback(Err(libc::EINVAL));
};
entry
Expand Down Expand Up @@ -313,7 +313,7 @@ impl FilesystemMT for ZerostashFS {
let stash = self.stash.lock().unwrap();
let index = &stash.index();
let tree = &index.tree;
let Ok(Some(entry)) = tree.get_file(path_string) else {
let Ok(Some(entry)) = tree.file(path_string) else {
return Err(libc::EINVAL);
};
entry
Expand Down Expand Up @@ -369,7 +369,7 @@ impl FilesystemMT for ZerostashFS {
let stash = self.stash.lock().unwrap();
let index = &stash.index();
let tree = &index.tree;
let Ok(Some(entry)) = tree.get_file(path_string) else {
let Ok(Some(entry)) = tree.file(path_string) else {
return Err(libc::EINVAL);
};
entry
Expand Down Expand Up @@ -547,7 +547,7 @@ impl FilesystemMT for ZerostashFS {
let mut index = stash.index().clone();

let tree = &mut index.tree;
let Ok(Some(entry)) = tree.get_file(&path_string) else {
let Ok(Some(entry)) = tree.file(&path_string) else {
return Err(libc::EINVAL)
};

Expand Down Expand Up @@ -581,7 +581,7 @@ impl FilesystemMT for ZerostashFS {
let mut index = stash.index().clone();

let tree = &mut index.tree;
let Ok(Some(entry)) = tree.get_file(&path_string) else {
let Ok(Some(entry)) = tree.file(&path_string) else {
return Err(libc::EINVAL)
};

Expand Down

0 comments on commit cc203d8

Please sign in to comment.