Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Jul 17, 2024
1 parent bf43e53 commit 90a882c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
28 changes: 15 additions & 13 deletions src/read/pipelining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ pub mod path_splitting {
FileDirOverlap(String),
}

fn split_by_separator<'a>(
entry_path: &'a str,
) -> Result<impl Iterator<Item = &'a str>, PathSplitError> {
fn split_by_separator(entry_path: &str) -> Result<impl Iterator<Item = &str>, PathSplitError> {

Check failure on line 20 in src/read/pipelining.rs

View workflow job for this annotation

GitHub Actions / Build and test --all-features: windows-latest, nightly

function `split_by_separator` is never used
if entry_path.contains('\\') {
if entry_path.contains('/') {
return Err(PathSplitError::PathFormat(format!(
Expand Down Expand Up @@ -152,20 +150,20 @@ pub mod path_splitting {
.entry(component)
.or_insert_with(|| Box::new(FSEntry::Dir(DirEntry::default())));
cur_dir = match next_subdir.as_mut() {
&mut FSEntry::File(_) => {
FSEntry::File(_) => {
return Err(PathSplitError::FileDirOverlap(format!(
"a file was already registered at the same path as the dir entry {:?}",
entry_path
)));
}
&mut FSEntry::Dir(ref mut subdir) => subdir,
FSEntry::Dir(ref mut subdir) => subdir,
}
}
match file_component {
Some(filename) => {
/* We can't handle duplicate file paths, as that might mess up our
* parallelization strategy. */
if let Some(_) = cur_dir.children.get(filename) {
if cur_dir.children.contains_key(filename) {
return Err(PathSplitError::FileDirOverlap(format!(
"another file or directory was already registered at the same path as the file entry {:?}",
entry_path
Expand All @@ -179,7 +177,7 @@ pub mod path_splitting {
/* We can't handle duplicate directory entries for the exact same normalized
* path, as it's not clear how to merge the possibility of two separate file
* permissions. */
if let Some(_) = cur_dir.properties.replace(data) {
if cur_dir.properties.replace(data).is_some() {
return Err(PathSplitError::FileDirOverlap(format!(
"another directory was already registered at the path {:?}",
entry_path
Expand Down Expand Up @@ -456,6 +454,7 @@ pub mod handle_creation {
* as a proxy. This should be considered if requested by users. */
fs::create_dir_all(top_level_extraction_dir)?;

#[allow(clippy::mutable_key_type)]
let mut file_handle_mapping: HashMap<ZipDataHandle<'a>, fs::File> = HashMap::new();
let mut entry_queue: VecDeque<(PathBuf, Box<FSEntry<'a, &'a ZipFileData>>)> =
lex_entry_trie
Expand Down Expand Up @@ -757,6 +756,7 @@ pub mod split_extraction {
) -> impl FnOnce() + Send + 'scope {
move || match f() {
Ok(()) => (),
#[allow(clippy::single_match)]
Err(e) => match err_sender.send(e) {
Ok(()) => (),
/* We use an async sender, so this should only error if the receiver has hung
Expand Down Expand Up @@ -804,7 +804,7 @@ pub mod split_extraction {
* sections in parallel across a thread pool. */
let input_file = FileInput::new(input_file)?;

thread::scope(move |ref scope| {
thread::scope(move |scope| {
/* (4) Create n parallel consumer pipelines. Threads are spawned into the scope, so
* panics get propagated automatically, and all threads are joined at the end of the
* scope. wrap_spawn_err() is used to enable thread closures to return a Result and
Expand Down Expand Up @@ -833,6 +833,7 @@ pub mod split_extraction {
/* Send this consumer pipeline's index to the zip-input-reader thread when it's
* ready to receive new input. */
let queue_sender = queue_sender.clone();
#[allow(clippy::single_match)]
let notify_readiness = move || match queue_sender.send(consumer_index) {
Ok(()) => (),
/* Disconnected; this is expected to occur at the end of extraction. */
Expand All @@ -856,7 +857,7 @@ pub mod split_extraction {
#[cfg(not(target_os = "linux"))]
let mut s = PipeReadBufferSplicer::new(&mut splice_buf);

for (ref entry, mut output_file) in uncompressed_receiver.iter() {
for (entry, mut output_file) in uncompressed_receiver.iter() {
s.splice_to_file_all(
&mut uncompressed_read_end,
(&mut output_file, 0),
Expand Down Expand Up @@ -891,7 +892,7 @@ pub mod split_extraction {
let mut buffer_allocation: Box<[u8]> =
vec![0u8; decompression_copy_buffer_length].into_boxed_slice();

for (ref entry, output_file) in compressed_receiver.iter() {
for (entry, output_file) in compressed_receiver.iter() {
/* Construct the decompressing reader. */
let limited_reader = ((&mut compressed_read_end)
as &mut dyn Read)
Expand Down Expand Up @@ -960,7 +961,7 @@ pub mod split_extraction {
* until we notify them. */
notify_readiness();

for (ref entry, data_start, mut output_file) in read_recv.iter() {
for (entry, data_start, mut output_file) in read_recv.iter() {
/* If uncompressed, we can use copy_file_range() directly, and
* avoid splicing through our decompression pipeline. */
if entry.compression_method == CompressionMethod::Stored {
Expand Down Expand Up @@ -1059,6 +1060,7 @@ pub mod split_extraction {
.spawn_scoped(
scope,
wrap_spawn_err(err_sender, move || {
#[allow(clippy::mutable_key_type)]
let mut file_handle_mapping = file_handle_mapping;
/* All consumer pipelines share the same channel to notify us of their
* identity when ready. */
Expand All @@ -1071,7 +1073,7 @@ pub mod split_extraction {

/* Entries are ordered by their offset, so we will be going monotonically
* forward in the underlying file. */
for ref entry in shared.files.values() {
for entry in shared.files.values() {
/* We have already created all necessary directories, and we set any
* dir perms after extracting file contents. */
if entry.is_dir() || entry.is_dir_by_mode() {
Expand Down Expand Up @@ -1112,7 +1114,7 @@ pub mod split_extraction {
/* If no I/O errors occurred, this won't trigger. We will only be able to propagate
* a single I/O error, but this also avoids propagating any errors triggered after the
* initial one. */
for err in err_receiver.iter() {
if let Some(err) = err_receiver.iter().next() {
return Err(err);
}

Expand Down
16 changes: 13 additions & 3 deletions src/read/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod file {
ops::Bound::Excluded(&end) => end,
ops::Bound::Unbounded => len,
};
#[allow(clippy::let_and_return)]
let clamped_end = unclamped_end.min(len);
clamped_end
};
Expand Down Expand Up @@ -140,6 +141,7 @@ pub mod file {
mut to: (&mut Self::OutF, u64),
len: usize,
) -> io::Result<()> {
#[allow(clippy::needless_borrow)]
let (ref from, from_offset) = from;
let (ref mut to, to_offset) = to;

Expand Down Expand Up @@ -314,6 +316,7 @@ pub mod file {
mut to: (&mut Self::OutF, u64),
len: usize,
) -> io::Result<usize> {
#[allow(clippy::needless_borrow)]
let (ref from, from_start) = from;
let (ref mut to, to_start) = to;

Expand Down Expand Up @@ -362,6 +365,7 @@ pub mod file {
Ok(i)
}

#[allow(clippy::missing_transmute_annotations)]
#[test]
fn pread() {
let i = readable_file(b"asdf").unwrap();
Expand Down Expand Up @@ -527,6 +531,7 @@ pub mod pipe {

use std::io;

#[allow(dead_code)]
pub trait WriteEnd: io::Write {}

pub trait WriteSplicer {
Expand All @@ -546,6 +551,7 @@ pub mod pipe {
to: &mut Self::OutP,
len: usize,
) -> io::Result<()> {
#[allow(clippy::needless_borrow)]
let (ref from, from_offset) = from;

let mut remaining_to_read: usize = len;
Expand All @@ -572,6 +578,7 @@ pub mod pipe {
}
}

#[allow(dead_code)]
pub trait ReadEnd: io::Read {}

pub trait ReadSplicer {
Expand Down Expand Up @@ -719,6 +726,7 @@ pub mod pipe {
}

impl<'infd, 'buf> PipeWriteBufferSplicer<'infd, 'buf> {
#[allow(dead_code)]
pub fn new(buf: &'buf mut [u8]) -> Self {
assert!(!buf.is_empty());
Self {
Expand All @@ -738,6 +746,7 @@ pub mod pipe {
to: &mut Self::OutP,
len: usize,
) -> io::Result<usize> {
#[allow(clippy::needless_borrow)]
let (ref from, from_start) = from;

let buf_clamped_len = len.min(self.buf.len());
Expand Down Expand Up @@ -773,6 +782,7 @@ pub mod pipe {
}

impl<'buf> PipeReadBufferSplicer<'buf> {
#[allow(dead_code)]
pub fn new(buf: &'buf mut [u8]) -> Self {
assert!(!buf.is_empty());
Self { buf }
Expand Down Expand Up @@ -894,7 +904,7 @@ pub mod pipe {
/* Get remaining chars written. */
buf.clear();
r.read_to_end(&mut buf).unwrap();
assert_eq!(&buf[..], &[b'd', b'f', b'a', b's', b'd', b'f']);
assert_eq!(&buf[..], b"dfasdf".as_ref());

t.join().unwrap().unwrap();
}
Expand Down Expand Up @@ -1051,7 +1061,7 @@ pub mod pipe {
/* Get remaining chars written. */
buf.clear();
r.read_to_end(&mut buf).unwrap();
assert_eq!(&buf[..], &[b'f', b'a', b's', b'd', b'f']);
assert_eq!(&buf[..], b"fasdf".as_ref());

t.join().unwrap().unwrap();
}
Expand Down Expand Up @@ -1155,7 +1165,7 @@ pub mod util {
let mut limited = TakeWrite::take(out, 3);
assert_eq!(3, limited.limit());

let mut buf = vec![0u8; 15];
let mut buf = [0u8; 15];

assert_eq!(
io::ErrorKind::WriteZero,
Expand Down

0 comments on commit 90a882c

Please sign in to comment.