Skip to content

Commit

Permalink
various: more clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
allisonkarlitskaya committed Oct 15, 2024
1 parent 1ea4cb5 commit 2d4135b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/dumpfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl<'a, W: Write> DumpfileWriter<'a, W> {
Self { hardlinks: HashMap::new(), writer }
}

fn write_dir(&mut self, mut path: &mut PathBuf, dir: &Directory) -> Result<()> {
fn write_dir(&mut self, path: &mut PathBuf, dir: &Directory) -> Result<()> {
// nlink is 2 + number of subdirectories
// this is also true for the root dir since '..' is another self-ref
let nlink = dir.entries.iter().fold(2, |count, ent| count + {
Expand All @@ -166,10 +166,10 @@ impl<'a, W: Write> DumpfileWriter<'a, W> {

match inode {
Inode::Directory(ref dir) => {
self.write_dir(&mut path, dir)?;
self.write_dir(path, dir)?;
},
Inode::Leaf(ref leaf) => {
self.write_leaf(&path, leaf)?;
self.write_leaf(path, leaf)?;
}
}

Expand All @@ -185,14 +185,14 @@ impl<'a, W: Write> DumpfileWriter<'a, W> {
// This is a hardlink. We need to handle that specially.
let ptr = Rc::as_ptr(leaf);
if let Some(target) = self.hardlinks.get(&ptr) {
return writeln_fmt(self.writer, |fmt| write_hardlink(fmt, &path, target));
return writeln_fmt(self.writer, |fmt| write_hardlink(fmt, path, target));
}

// @path gets modified all the time, so take a copy
self.hardlinks.insert(ptr, OsString::from(&path));
}

writeln_fmt(self.writer, |fmt| write_leaf(fmt, &path, &leaf.stat, &leaf.content, nlink))
writeln_fmt(self.writer, |fmt| write_leaf(fmt, path, &leaf.stat, &leaf.content, nlink))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl Directory {
// iteration of the binary search.
if let Some(last_entry) = self.entries.last() {
match name.cmp(&last_entry.name) {
Ordering::Equal => return Ok(self.entries.len() - 1), // the last item, indeed
Ordering::Greater => return Err(self.entries.len()), // need to append
Ordering::Equal => Ok(self.entries.len() - 1), // the last item, indeed
Ordering::Greater => Err(self.entries.len()), // need to append
Ordering::Less => self.entries.binary_search_by_key(&name, |e| &e.name)
}
} else {
Expand Down
7 changes: 3 additions & 4 deletions src/oci/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ pub fn process_entry(filesystem: &mut FileSystem, entry: oci::tar::TarEntry) ->

let mut dir = &mut filesystem.root;
for component in components {
match component {
Component::Normal(name) => { dir = dir.recurse(name)?; },
_ => { }
if let Component::Normal(name) = component {
dir = dir.recurse(name)?;
}
}

Expand Down Expand Up @@ -153,7 +152,7 @@ fn assert_files(fs: &FileSystem, expected: &[&str]) -> Result<()> {
write_dumpfile(&mut out, fs)?;
let actual: Vec<String> = out
.lines()
.map(|line| line.unwrap().split_once(|c| c == ' ').unwrap().0.into() )
.map(|line| line.unwrap().split_once(' ').unwrap().0.into() )
.collect();

assert_eq!(actual, expected);
Expand Down

0 comments on commit 2d4135b

Please sign in to comment.