tail: show end of device

gnu coreutils will show end of device for block devices.
In current implementation this is skipped as a block devices
are recognized as untailable.

The change ensures that we first try to output the end of any
file and only then tell the observer that the file is not
observable.
This commit is contained in:
Martin Kunkel
2025-07-16 18:54:40 +02:00
parent 142d920fbd
commit 24a556b8b7
+11 -9
View File
@@ -177,7 +177,7 @@ fn tail_file(
return Ok(());
}
observer.add_bad_path(path, input.display_name.as_str(), false)?;
} else if input.is_tailable() {
} else {
match File::open(path) {
Ok(mut file) => {
let st = file.metadata()?;
@@ -194,12 +194,16 @@ fn tail_file(
reader = BufReader::new(file);
unbounded_tail(&mut reader, settings)?;
}
observer.add_path(
path,
input.display_name.as_str(),
Some(Box::new(reader)),
true,
)?;
if input.is_tailable() {
observer.add_path(
path,
input.display_name.as_str(),
Some(Box::new(reader)),
true,
)?;
} else {
observer.add_bad_path(path, input.display_name.as_str(), false)?;
}
}
Err(e) if e.kind() == ErrorKind::PermissionDenied => {
observer.add_bad_path(path, input.display_name.as_str(), false)?;
@@ -220,8 +224,6 @@ fn tail_file(
}));
}
}
} else {
observer.add_bad_path(path, input.display_name.as_str(), false)?;
}
Ok(())