Watch
0
0
Fork
You've already forked hyperhive
0

swarm-builder: keep a cut last line that is longer than the window

After a cut, Tail::finish dropped everything through the first newline.
When the stream ended in one line longer than the window, that newline
was the last byte, so the window came back empty and the reply fell back
to the bare exit status. The cut line is now dropped only when something
follows it.
This commit is contained in:
atlas 2026-10-16 23:19:00 +02:00 • committed by mara
commit 88dd58e947

View file

@ -237,14 +237,15 @@ impl Tail {
}
/// The kept bytes. When the stream was longer than `keep`, the cut line
/// at the front is dropped, so the result starts on a line boundary
/// (unless it holds no newline at all).
/// at the front is dropped, so the result starts on a line boundary,
/// unless that line is all the window holds.
fn finish(mut self) -> Vec<u8> {
if self.buf.len() > self.keep {
self.trim();
}
if self.cut
&& let Some(nl) = self.buf.iter().position(|&b| b == b'\n')
&& nl + 1 < self.buf.len()
{
self.buf.drain(..=nl);
}
@ -566,6 +567,10 @@ mod tests {
assert_eq!(String::from_utf8(cut).expect("utf-8"), "cccc\ndddd\n");
let one_long_line = read_tail(&b"x".repeat(50)[..], 12).await.expect("read");
assert_eq!(one_long_line, b"x".repeat(12));
let long_last_line = read_tail(format!("{}\n", "x".repeat(50)).as_bytes(), 12)
.await
.expect("read");
assert_eq!(long_last_line, format!("{}\n", "x".repeat(11)).as_bytes());
}
#[test]