Skip to content

Commit f4599d0

Browse files
basenc: ignore Interrupted errors
Mirror behavior of `std::io::Read`'s `read_to_end` function ([link][1]): continue reading when errors with kind `std::io::ErrorKind::Interrupted` are encountered. Also: clean up a few other things. [1]: https://doc.rust-lang.org/std/io/trait.Read.html#method.read_to_end
1 parent 3564b5c commit f4599d0

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/uu/base32/src/base_common.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub fn get_input(config: &Config) -> UResult<Box<dyn Read>> {
160160
}
161161
}
162162

163-
pub fn handle_input<R: Read>(input: &mut R, format: Format, config: Config) -> UResult<()> {
163+
pub fn handle_input(input: &mut dyn Read, format: Format, config: Config) -> UResult<()> {
164164
let supports_fast_decode_and_encode = get_supports_fast_decode_and_encode(format);
165165

166166
let supports_fast_decode_and_encode_ref = supports_fast_decode_and_encode.as_ref();
@@ -377,13 +377,13 @@ pub mod fast_encode {
377377
}
378378

379379
fn write_to_output(
380-
line_wrapping_option: &mut Option<LineWrapping>,
380+
line_wrapping: &mut Option<LineWrapping>,
381381
encoded_buffer: &mut VecDeque<u8>,
382382
output: &mut dyn Write,
383383
is_cleanup: bool,
384384
) -> io::Result<()> {
385385
// Write all data in `encoded_buffer` to `output`
386-
if let &mut Some(ref mut li) = line_wrapping_option {
386+
if let &mut Some(ref mut li) = line_wrapping {
387387
write_with_line_breaks(li, encoded_buffer, output, is_cleanup)?;
388388
} else {
389389
write_without_line_breaks(encoded_buffer, output, is_cleanup)?;
@@ -393,9 +393,9 @@ pub mod fast_encode {
393393
}
394394
// End of helper functions
395395

396-
pub fn fast_encode<R: Read, W: Write>(
397-
input: &mut R,
398-
mut output: W,
396+
pub fn fast_encode(
397+
input: &mut dyn Read,
398+
output: &mut dyn Write,
399399
supports_fast_decode_and_encode: &dyn SupportsFastDecodeAndEncode,
400400
wrap: Option<usize>,
401401
) -> UResult<()> {
@@ -475,14 +475,14 @@ pub mod fast_encode {
475475
assert!(leftover_buffer.len() < encode_in_chunks_of_size);
476476

477477
// Write all data in `encoded_buffer` to `output`
478-
write_to_output(&mut line_wrapping, &mut encoded_buffer, &mut output, false)?;
478+
write_to_output(&mut line_wrapping, &mut encoded_buffer, output, false)?;
479479
}
480480
Err(er) => {
481481
let kind = er.kind();
482482

483483
if kind == ErrorKind::Interrupted {
484-
// TODO
485-
// Retry reading?
484+
// Retry reading
485+
continue;
486486
}
487487

488488
return Err(USimpleError::new(1, format_read_error(kind)));
@@ -499,7 +499,7 @@ pub mod fast_encode {
499499

500500
// Write all data in `encoded_buffer` to output
501501
// `is_cleanup` triggers special cleanup-only logic
502-
write_to_output(&mut line_wrapping, &mut encoded_buffer, &mut output, true)?;
502+
write_to_output(&mut line_wrapping, &mut encoded_buffer, output, true)?;
503503
}
504504

505505
Ok(())
@@ -606,9 +606,9 @@ pub mod fast_decode {
606606
}
607607
// End of helper functions
608608

609-
pub fn fast_decode<R: Read, W: Write>(
610-
input: &mut R,
611-
mut output: &mut W,
609+
pub fn fast_decode(
610+
input: &mut dyn Read,
611+
output: &mut dyn Write,
612612
supports_fast_decode_and_encode: &dyn SupportsFastDecodeAndEncode,
613613
ignore_garbage: bool,
614614
) -> UResult<()> {
@@ -711,14 +711,14 @@ pub mod fast_decode {
711711
assert!(leftover_buffer.len() < decode_in_chunks_of_size);
712712

713713
// Write all data in `decoded_buffer` to `output`
714-
write_to_output(&mut decoded_buffer, &mut output)?;
714+
write_to_output(&mut decoded_buffer, output)?;
715715
}
716716
Err(er) => {
717717
let kind = er.kind();
718718

719719
if kind == ErrorKind::Interrupted {
720-
// TODO
721-
// Retry reading?
720+
// Retry reading
721+
continue;
722722
}
723723

724724
return Err(USimpleError::new(1, format_read_error(kind)));
@@ -734,7 +734,7 @@ pub mod fast_decode {
734734
.decode_into_vec(&leftover_buffer, &mut decoded_buffer)?;
735735

736736
// Write all data in `decoded_buffer` to `output`
737-
write_to_output(&mut decoded_buffer, &mut output)?;
737+
write_to_output(&mut decoded_buffer, output)?;
738738
}
739739

740740
Ok(())

src/uu/paste/src/paste.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn parse_delimiters(delimiters: &str) -> UResult<Box<[Box<[u8]>]>> {
200200
let mut add_single_char_delimiter = |vec: &mut Vec<Box<[u8]>>, ch: char| {
201201
let delimiter_encoded = ch.encode_utf8(&mut buffer);
202202

203-
vec.push(Box::from(delimiter_encoded.as_bytes()));
203+
vec.push(Box::<[u8]>::from(delimiter_encoded.as_bytes()));
204204
};
205205

206206
let mut vec = Vec::<Box<[u8]>>::with_capacity(delimiters.len());
@@ -311,7 +311,7 @@ impl<'a> DelimiterState<'a> {
311311
DelimiterState::MultipleDelimiters {
312312
current_delimiter, ..
313313
} => current_delimiter.len(),
314-
_ => {
314+
DelimiterState::NoDelimiters => {
315315
return;
316316
}
317317
};
@@ -350,7 +350,7 @@ impl<'a> DelimiterState<'a> {
350350

351351
*current_delimiter = bo;
352352
}
353-
_ => {}
353+
DelimiterState::NoDelimiters => {}
354354
}
355355
}
356356
}
@@ -363,8 +363,8 @@ enum InputSource {
363363
impl InputSource {
364364
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> UResult<usize> {
365365
let us = match self {
366-
Self::File(bu) => bu.read_until(byte, buf)?,
367-
Self::StandardInput(rc) => rc
366+
InputSource::File(bu) => bu.read_until(byte, buf)?,
367+
InputSource::StandardInput(rc) => rc
368368
.try_borrow()
369369
.map_err(|bo| USimpleError::new(1, format!("{bo}")))?
370370
.lock()

0 commit comments

Comments
 (0)