From 22265814ba5cb0c163a32526b5c5ece4ee49a73c Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 17 Jun 2021 14:49:08 -0700 Subject: [PATCH] Cleans up compiler warnings. --- src/uu/dd/src/dd.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 5eccf032a..585300d68 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -19,7 +19,7 @@ mod conversion_tables; use conversion_tables::*; use byte_unit::Byte; -#[macro_use] +// #[macro_use] use debug_print::debug_println; use gcd::Gcd; use getopts; @@ -422,7 +422,7 @@ impl Input /// Fills a given buffer. /// Reads in increments of 'self.ibs'. /// The start of each ibs-sized read is aligned to multiples of ibs; remaing space is filled with the 'pad' byte. - fn fill_blocks(&mut self, buf: &mut Vec, obs: usize, pad: u8) -> Result> + fn fill_blocks(&mut self, buf: &mut Vec, pad: u8) -> Result> { let mut reads_complete = 0; let mut reads_partial = 0; @@ -480,7 +480,7 @@ impl Input /// interpreted as EOF. /// Note: This will not return unless the source (eventually) produces /// enough bytes to meet target_len. - fn force_fill(&mut self, mut buf: &mut [u8], target_len: usize) -> Result> + fn force_fill(&mut self, buf: &mut [u8], target_len: usize) -> Result> { let mut base_idx = 0; while base_idx < target_len @@ -711,7 +711,7 @@ impl Output }, wlen => { - writes_partial += 1; + writes_complete += 1; base_idx += wlen; }, } @@ -736,17 +736,21 @@ impl Output while base_idx < buf.len() { let next_blk = cmp::min(base_idx+self.obs, buf.len()); - let wlen = self.write(&buf[base_idx..next_blk])?; + let plen = next_blk - base_idx; - if wlen == self.obs + match self.write(&buf[base_idx..next_blk])? { - writes_complete += 1; + wlen if wlen < plen => + { + writes_partial += 1; + base_idx += wlen; + }, + wlen => + { + writes_complete += 1; + base_idx += wlen; + }, } - else - { - writes_partial += 1; - } - base_idx += wlen; } Ok(WriteStat { @@ -840,7 +844,7 @@ fn unblock(buf: Vec, cbs: usize) -> Vec .collect() } -fn conv_block_unblock_helper(mut buf: Vec, i: &mut Input, o: &Output, rstat: &mut ReadStat) -> Result, Box> +fn conv_block_unblock_helper(mut buf: Vec, i: &mut Input, rstat: &mut ReadStat) -> Result, Box> { // Local Predicate Fns ------------------------------------------------- #[inline] @@ -963,7 +967,7 @@ fn conv_block_unblock_helper(mut buf: Vec, i: &mut Input< } } -fn read_helper(i: &mut Input, o: &mut Output, bsize: usize) -> Result<(ReadStat, Vec), Box> +fn read_helper(i: &mut Input, bsize: usize) -> Result<(ReadStat, Vec), Box> { // Local Predicate Fns ----------------------------------------------- #[inline] @@ -1000,7 +1004,7 @@ fn read_helper(i: &mut Input, o: &mut Output, bsize: us let mut rstat = match i.cflags.sync { Some(ch) => - i.fill_blocks(&mut buf, o.obs, ch)?, + i.fill_blocks(&mut buf, ch)?, _ => i.fill_consecutive(&mut buf)?, }; @@ -1017,7 +1021,7 @@ fn read_helper(i: &mut Input, o: &mut Output, bsize: us } if is_conv(&i) || is_block(&i) || is_unblock(&i) { - let buf = conv_block_unblock_helper(buf, i, o, &mut rstat)?; + let buf = conv_block_unblock_helper(buf, i, &mut rstat)?; Ok((rstat, buf)) } else @@ -1222,7 +1226,7 @@ fn dd_stdout(mut i: Input, mut o: Output) -> Result<(), { // Read/Write let loop_bsize = calc_loop_bsize(&i.count, &rstat, &wstat, i.ibs, bsize); - match read_helper(&mut i, &mut o, loop_bsize)? + match read_helper(&mut i, loop_bsize)? { (ReadStat { reads_complete: 0, reads_partial: 0, .. }, _) => break, @@ -1301,7 +1305,7 @@ fn dd_fileout(mut i: Input, mut o: Output) -> Result<(), Box break,