Skip to content

Commit

Permalink
Accept whole sequence names as indices in get/
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Oct 24, 2022
1 parent 228c5af commit 860b3be
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

pkgs.mkShell {
buildInputs = [
pkgs.fuse pkgs.cargo pkgs.pkg-config pkgs.rustfmt pkgs.libiconv pkgs.rustc pkgs.clippy
pkgs.fuse pkgs.cargo pkgs.pkg-config pkgs.rustfmt pkgs.libiconv pkgs.rustc pkgs.clippy pkgs.rustfmt
];
}
71 changes: 42 additions & 29 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,36 +876,49 @@ impl FustaFS {

fn create_subfragment(&mut self, name: &str) -> Result<FileAttr, String> {
let error_message = format!("`{}` is not a valid subfragment scheme", name);

let caps = SUBFRAGMENT_RE
.captures(name)
.ok_or_else(|| format!("{}: it should be of the form ID:START-END", error_message))?;
if caps.len() == 4 {
let ino = self.new_ino();
let fragment_id = self
.fragment_from_id(&caps[1])
.ok_or_else(|| format!("`{}` is not a fragment", &caps[1]))?
.id
.clone();
let start = str::parse::<usize>(&caps[2])
.map_err(|_| format!("{}: `{}` is not an integer", &error_message, &caps[1]))?;
let end = str::parse::<usize>(&caps[3])
.map_err(|_| format!("{}: `{}` is not an integer", &error_message, &caps[2]))?;

self.subfragments
.iter()
.find(|sf| sf.fragment == fragment_id && sf.start == start && sf.end == end)
.map(|sf| sf.attrs)
.or_else(|| {
let mut attrs = FustaFS::make_file_attrs(ino, 0o444);
attrs.size = (end - start) as u64;
let sf = SubFragment::new(&fragment_id, start, end, attrs);
self.subfragments.push(sf);
Some(attrs)
})
.ok_or_else(|| unimplemented!())
if name.contains(':') && name.contains(':') {
let caps = SUBFRAGMENT_RE.captures(name).ok_or_else(|| {
format!("{}: it should be of the form ID:START-END", error_message)
})?;
if caps.len() == 4 {
let ino = self.new_ino();
let fragment_id = self
.fragment_from_id(&caps[1])
.ok_or_else(|| format!("`{}` is not a fragment", &caps[1]))?
.id
.clone();
let start = str::parse::<usize>(&caps[2])
.map_err(|_| format!("{}: `{}` is not an integer", &error_message, &caps[1]))?;
let end = str::parse::<usize>(&caps[3])
.map_err(|_| format!("{}: `{}` is not an integer", &error_message, &caps[2]))?;

self.subfragments
.iter()
.find(|sf| sf.fragment == fragment_id && sf.start == start && sf.end == end)
.map(|sf| sf.attrs)
.or_else(|| {
let mut attrs = FustaFS::make_file_attrs(ino, 0o444);
attrs.size = (end - start) as u64;
let sf = SubFragment::new(&fragment_id, start, end, attrs);
self.subfragments.push(sf);
Some(attrs)
})
.ok_or_else(|| unimplemented!())
} else {
Err(error_message)
}
} else {
Err(error_message)
let ino = self.new_ino();
let fragment = self
.fragment_from_id(name)
.ok_or_else(|| format!("`{}` is not a fragment", name))?;
let fragment_id = fragment.id.clone();
let fragment_len = fragment.data.len();
let mut attrs = FustaFS::make_file_attrs(ino, 0o444);
attrs.size = fragment_len as u64;
let sf = SubFragment::new(&fragment_id, 0, fragment_len, attrs);
self.subfragments.push(sf);
Ok(attrs)
}
}
}
Expand Down

0 comments on commit 860b3be

Please sign in to comment.