mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
commit
1d794e1a94
1 changed files with 13 additions and 18 deletions
|
@ -191,7 +191,7 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
|
|||
|
||||
if use_stdin {
|
||||
let mut reader = BufReader::new(stdin());
|
||||
unbounded_tail(&mut reader, settings);
|
||||
unbounded_tail(&mut reader, settings)?;
|
||||
|
||||
// Don't follow stdin since there are no checks for pipes/FIFOs
|
||||
//
|
||||
|
@ -230,7 +230,7 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
|
|||
}
|
||||
} else {
|
||||
let mut reader = BufReader::new(file);
|
||||
unbounded_tail(&mut reader, settings);
|
||||
unbounded_tail(&mut reader, settings)?;
|
||||
if settings.follow {
|
||||
readers.push((Box::new(reader), filename));
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ fn uu_tail(settings: &Settings) -> UResult<()> {
|
|||
}
|
||||
|
||||
if settings.follow {
|
||||
follow(&mut readers[..], settings);
|
||||
follow(&mut readers[..], settings)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -342,10 +342,9 @@ pub fn uu_app() -> App<'static, 'static> {
|
|||
)
|
||||
}
|
||||
|
||||
fn follow<T: BufRead>(readers: &mut [(T, &String)], settings: &Settings) {
|
||||
assert!(settings.follow);
|
||||
if readers.is_empty() {
|
||||
return;
|
||||
fn follow<T: BufRead>(readers: &mut [(T, &String)], settings: &Settings) -> UResult<()> {
|
||||
if readers.is_empty() || !settings.follow {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut last = readers.len() - 1;
|
||||
|
@ -372,7 +371,7 @@ fn follow<T: BufRead>(readers: &mut [(T, &String)], settings: &Settings) {
|
|||
}
|
||||
print!("{}", datum);
|
||||
}
|
||||
Err(err) => panic!("{}", err),
|
||||
Err(err) => return Err(USimpleError::new(1, err.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -381,6 +380,7 @@ fn follow<T: BufRead>(readers: &mut [(T, &String)], settings: &Settings) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Iterate over bytes in the file, in reverse, until we find the
|
||||
|
@ -475,7 +475,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) {
|
||||
fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UResult<()> {
|
||||
// Read through each line/char and store them in a ringbuffer that always
|
||||
// contains count lines/chars. When reaching the end of file, output the
|
||||
// data in the ringbuf.
|
||||
|
@ -487,11 +487,13 @@ fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) {
|
|||
}
|
||||
FilterMode::Bytes(count) => {
|
||||
for byte in unbounded_tail_collect(reader.bytes(), count, settings.beginning) {
|
||||
let mut stdout = stdout();
|
||||
print_byte(&mut stdout, byte);
|
||||
if let Err(err) = stdout().write(&[byte]) {
|
||||
return Err(USimpleError::new(1, err.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_seekable<T: Seek>(file: &mut T) -> bool {
|
||||
|
@ -500,13 +502,6 @@ fn is_seekable<T: Seek>(file: &mut T) -> bool {
|
|||
&& file.seek(SeekFrom::Start(0)).is_ok()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn print_byte<T: Write>(stdout: &mut T, ch: u8) {
|
||||
if let Err(err) = stdout.write(&[ch]) {
|
||||
crash!(1, "{}", err);
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_num(src: &str) -> Result<(usize, bool), ParseSizeError> {
|
||||
let mut size_string = src.trim();
|
||||
let mut starting_with = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue