mirror of
https://github.com/aphrody-labs/uutils-coreutils.git
synced 2026-10-17 12:45:53 +00:00
Revert "tail: stop reading past the original end of file"
This reverts commit 781ddfc58c.
This commit is contained in:
1 parent
50b4911bb2
commit
072331e88c
2 files changed
+2
-39
No files matched your search
+2
-11
@@ -178,7 +178,7 @@ fn tail_file(
|
||||
&& file.is_seekable(if input.is_stdin() { offset } else { 0 })
|
||||
&& (!st.is_file() || st.len() > blksize_limit)
|
||||
{
|
||||
bounded_tail(&mut file, settings, st.is_file().then_some(st.len()))?;
|
||||
bounded_tail(&mut file, settings)?;
|
||||
reader = BufReader::new(file);
|
||||
} else {
|
||||
reader = BufReader::new(file);
|
||||
@@ -452,7 +452,7 @@ fn backwards_thru_file(file: &mut File, num_delimiters: u64, delimiter: u8) {
|
||||
/// end of the file, and then read the file "backwards" in blocks of size
|
||||
/// `BLOCK_SIZE` until we find the location of the first line/byte. This ends up
|
||||
/// being a nice performance win for very large files.
|
||||
fn bounded_tail(file: &mut File, settings: &Settings, file_size: Option<u64>) -> UResult<()> {
|
||||
fn bounded_tail(file: &mut File, settings: &Settings) -> UResult<()> {
|
||||
debug_assert!(!settings.presume_input_pipe);
|
||||
let mut limit = None;
|
||||
|
||||
@@ -460,15 +460,6 @@ fn bounded_tail(file: &mut File, settings: &Settings, file_size: Option<u64>) ->
|
||||
match &settings.mode {
|
||||
FilterMode::Lines(Signum::Negative(count), delimiter) => {
|
||||
backwards_thru_file(file, *count, *delimiter);
|
||||
// Print only up to the end the file had when it was opened.
|
||||
// Otherwise, if the output is appended back to the input file
|
||||
// (e.g. `tail -n1 f >> f`), reading until EOF never terminates
|
||||
// because our own output keeps extending it.
|
||||
if let Some(size) = file_size
|
||||
&& let Ok(pos) = file.stream_position()
|
||||
{
|
||||
limit = Some(size.saturating_sub(pos));
|
||||
}
|
||||
}
|
||||
FilterMode::Lines(Signum::Positive(count), delimiter) if count > &1 => {
|
||||
let i = forwards_thru_file(file, *count - 1, *delimiter).unwrap();
|
||||
|
||||
@@ -263,34 +263,6 @@ fn test_n0_with_follow() {
|
||||
child.kill();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
#[cfg_attr(wasi_runner, ignore = "WASI: no rlimit support")]
|
||||
fn test_output_appended_to_input_file_terminates() {
|
||||
// $ tail -n1 f >> f
|
||||
// Appends the last line once and exits; it must not read back its
|
||||
// own output forever. The file size limit makes a broken
|
||||
// implementation fail instead of filling the disk.
|
||||
use rustix::process::Resource;
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
// Larger than the filesystem block size so `tail` reads from the end.
|
||||
let content = "x".repeat(256 * 1024) + "\n";
|
||||
at.write("f", &content);
|
||||
let out = std::fs::OpenOptions::new()
|
||||
.append(true)
|
||||
.open(at.plus("f"))
|
||||
.unwrap();
|
||||
|
||||
ucmd.args(&["-n1", "f"])
|
||||
.set_stdout(Stdio::from(out))
|
||||
.limit(Resource::Fsize, 4 * 1024 * 1024, 4 * 1024 * 1024)
|
||||
.succeeds();
|
||||
|
||||
assert_eq!(at.read("f"), content.repeat(2));
|
||||
}
|
||||
|
||||
// TODO: Add similar test for windows
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
|
||||
Reference in new issue
Block a user