Skip to content

Commit

Permalink
vfs path res correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
corigan01 committed Nov 22, 2023
1 parent c7fd205 commit 6a53bcc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
34 changes: 33 additions & 1 deletion lib/fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ mod test {
todo!()
}
fn rm(&mut self, path: crate::path::Path) -> FsResult<()> {
todo!()
Err(FsError::new(FsErrorKind::Other, path.as_str().into()))
}
}

Expand Down Expand Up @@ -487,4 +487,36 @@ mod test {
== FsErrorKind::StorageFull
);
}

#[test]
fn test_vfs_path_resl_correctly() {
crate::set_example_allocator();

let mut vfs = Vfs::new();
assert_eq!(
vfs.mount(Path::from("/"), Box::new(SuperFakeFs::new())),
Ok(0)
);
assert_eq!(
vfs.mount(Path::from("/test"), Box::new(SuperFakeFs::new())),
Ok(1)
);

assert_eq!(
vfs.rm("/test/fs.txt".into()).unwrap_err().into_inner(),
"/fs.txt"
);

assert_eq!(
vfs.rm("/fs.txt".into()).unwrap_err().into_inner(),
"/fs.txt"
);

assert_eq!(
vfs.rm("/still_root/fs.txt".into())
.unwrap_err()
.into_inner(),
"/still_root/fs.txt"
);
}
}
6 changes: 5 additions & 1 deletion lib/fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ impl Path {
}

pub fn snip_off(self, path: Path) -> Option<Path> {
let path = path.truncate_path();
let mut path = path.truncate_path();

if path.0.ends_with("/") {
path = Path(path.0.as_str()[..path.0.len() - 1].into())
}

if !self.0.starts_with(path.as_str()) {
return None;
Expand Down

0 comments on commit 6a53bcc

Please sign in to comment.