Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
bbqsrc committed Feb 5, 2024
1 parent 0541fbe commit 4fd16ac
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 31 deletions.
8 changes: 4 additions & 4 deletions box-format/src/file/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'a> Iterator for Records<'a> {
if let Record::Directory(record) = record {
self.cur_dir = Some(Box::new(Records::new(
self.meta,
&*record.inodes,
&record.inodes,
Some(base_path.clone()),
)));
}
Expand Down Expand Up @@ -153,7 +153,7 @@ impl<'a> Iterator for FindRecord<'a> {
} else if let Record::Directory(record) = v.1 {
let mut tmp = VecDeque::new();
std::mem::swap(&mut self.query, &mut tmp);
let result = FindRecord::new(self.meta, tmp, &*record.inodes).next();
let result = FindRecord::new(self.meta, tmp, &record.inodes).next();
log::debug!("FindRecord result: {:?}", &result);
result
} else {
Expand All @@ -168,7 +168,7 @@ impl<'a> Iterator for FindRecord<'a> {
impl BoxMetadata {
#[inline(always)]
pub fn iter(&self) -> Records {
Records::new(self, &*self.root, None)
Records::new(self, &self.root, None)
}

#[inline(always)]
Expand Down Expand Up @@ -196,7 +196,7 @@ impl BoxMetadata {
// return Inode::new(inode).ok();
// };

FindRecord::new(self, path.iter().map(str::to_string).collect(), &*self.root).next()
FindRecord::new(self, path.iter().map(str::to_string).collect(), &self.root).next()
}

#[inline(always)]
Expand Down
27 changes: 12 additions & 15 deletions box-format/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,40 +66,37 @@ mod tests {
#[test]
fn read_garbage() {
let filename = "./read_garbage.box";
create_test_box(&filename);
create_test_box(filename);

let bf = BoxFileReader::open(&filename).unwrap();
let bf = BoxFileReader::open(filename).unwrap();
let trailer = bf.metadata();
println!("{:?}", bf.header);
println!("{:?}", &trailer);
let file_data = unsafe {
bf.memory_map(&trailer.inodes[0].as_file().unwrap())
.unwrap()
};
let file_data = unsafe { bf.memory_map(trailer.inodes[0].as_file().unwrap()).unwrap() };
println!("{:?}", &*file_data);
assert_eq!(&*file_data, b"hello\0\0\0")
}

#[test]
fn create_garbage() {
let filename = "./create_garbage.box";
let _ = std::fs::remove_file(&filename);
let bf = BoxFileWriter::create(&filename).expect("Mah box");
let _ = std::fs::remove_file(filename);
let bf = BoxFileWriter::create(filename).expect("Mah box");
bf.finish().unwrap();
}

#[test]
fn read_bytes() {
let filename = "./read_bytes.box";
create_test_box(&filename);
let bf = BoxFileReader::open(&filename).unwrap();
create_test_box(filename);
let bf = BoxFileReader::open(filename).unwrap();
let record = bf
.metadata()
.inodes
.first()
.map(|f| f.as_file().unwrap())
.unwrap();
let mut reader = bf.read_bytes(&record).unwrap();
let mut reader = bf.read_bytes(record).unwrap();
let mut vec = vec![];
reader.read_to_end(&mut vec).unwrap();
assert_eq!(vec, b"hello\0\0\0")
Expand All @@ -109,7 +106,7 @@ mod tests {
where
F: Fn(&str) -> BoxFileWriter,
{
let _ = std::fs::remove_file(&filename);
let _ = std::fs::remove_file(filename);
let v =
"This, this, this, this, this is a compressable string string string string string.\n"
.to_string();
Expand Down Expand Up @@ -152,17 +149,17 @@ mod tests {
bf.finish().unwrap();
}

let bf = BoxFileReader::open(&filename).expect("Mah box");
let bf = BoxFileReader::open(filename).expect("Mah box");
println!("{:#?}", &bf);

assert_eq!(
v,
bf.decompress_value::<String>(&bf.meta.inodes[1].as_file().unwrap())
bf.decompress_value::<String>(bf.meta.inodes[1].as_file().unwrap())
.unwrap()
);
assert_eq!(
v,
bf.decompress_value::<String>(&bf.meta.inodes[2].as_file().unwrap())
bf.decompress_value::<String>(bf.meta.inodes[2].as_file().unwrap())
.unwrap()
);
}
Expand Down
4 changes: 2 additions & 2 deletions box-format/src/file/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl BoxFileReader {
// println!("{} -> {}: {:?}", path, output_path.display(), record);
match record {
Record::File(file) => {
fs::create_dir_all(&output_path)
fs::create_dir_all(output_path)
.map_err(|e| ExtractError::CreateDirFailed(e, output_path.to_path_buf()))?;
let out_path = output_path.join(path.to_path_buf());
let mut out_file = std::fs::OpenOptions::new();
Expand Down Expand Up @@ -297,7 +297,7 @@ impl BoxFileReader {
Ok(())
}
Record::Directory(_dir) => {
fs::create_dir_all(&output_path)
fs::create_dir_all(output_path)
.map_err(|e| ExtractError::CreateDirFailed(e, output_path.to_path_buf()))?;
let new_dir = output_path.join(path.to_path_buf());
fs::create_dir(&new_dir).map_err(|e| ExtractError::CreateDirFailed(e, new_dir))
Expand Down
4 changes: 2 additions & 2 deletions box-format/src/file/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl BoxFileWriter {
self.file.seek(SeekFrom::Start(pos))?;
self.meta.write(&mut self.file)?;

let new_pos = self.file.seek(SeekFrom::Current(0))?;
let new_pos = self.file.stream_position()?;
let file = self.file.get_mut();
file.set_len(new_pos)?;
Ok(new_pos)
Expand Down Expand Up @@ -181,7 +181,7 @@ impl BoxFileWriter {

#[inline(always)]
fn iter(&self) -> super::meta::Records {
super::meta::Records::new(self.metadata(), &*self.metadata().root, None)
super::meta::Records::new(self.metadata(), &self.metadata().root, None)
}

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion box-format/src/path/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl BoxPath {
}

pub fn join<P: AsRef<Path>>(&self, tail: P) -> std::result::Result<BoxPath, IntoBoxPathError> {
Self::new(&self.to_path_buf().join(tail))
Self::new(self.to_path_buf().join(tail))
}

pub(crate) fn join_unchecked(&self, tail: &str) -> BoxPath {
Expand Down
6 changes: 3 additions & 3 deletions box-format/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ impl Record {
#[inline(always)]
pub fn name(&self) -> &str {
match self {
Record::File(file) => &*file.name,
Record::Directory(dir) => &*dir.name,
Record::Link(link) => &*link.name,
Record::File(file) => &file.name,
Record::Directory(dir) => &dir.name,
Record::Link(link) => &link.name,
}
}

Expand Down
6 changes: 3 additions & 3 deletions box-format/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Serialize for String {
impl Serialize for Vec<u8> {
fn write<W: Write + Seek>(&self, writer: &mut W) -> std::io::Result<()> {
writer.write_vu64(self.len() as u64)?;
writer.write_all(&*self)
writer.write_all(self)
}
}

Expand All @@ -42,7 +42,7 @@ impl Serialize for AttrMap {
// Write the length in bytes so implementations can skip the entire map if they so choose.

// Write it as u64::MAX, then seek back
let size_index = writer.seek(SeekFrom::Current(0))?;
let size_index = writer.stream_position()?;
writer.write_u64::<LittleEndian>(std::u64::MAX)?;
writer.write_vu64(self.len() as u64)?;

Expand All @@ -52,7 +52,7 @@ impl Serialize for AttrMap {
}

// Go back and write size
let cur_index = writer.seek(SeekFrom::Current(0))?;
let cur_index = writer.stream_position()?;
writer.seek(SeekFrom::Start(size_index))?;
writer.write_u64::<LittleEndian>(cur_index - size_index)?;
writer.seek(SeekFrom::Start(cur_index))?;
Expand Down
2 changes: 1 addition & 1 deletion box/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ fn process_files<I: Iterator<Item = PathBuf>>(
mut known_files: HashSet<BoxPath>,
) -> Result<()> {
let iter = iter.flat_map(|path| {
let mut walker = jwalk::WalkDir::new(&path).sort(true);
let mut walker = jwalk::WalkDir::new(path).sort(true);
if !recursive {
walker = walker.parallelism(jwalk::Parallelism::Serial).max_depth(0);
}
Expand Down

0 comments on commit 4fd16ac

Please sign in to comment.