Skip to content

sed: flush named output files with -u - #663

Open
Himanshu-singh04 wants to merge 2 commits into
uutils:mainfrom
Himanshu-singh04:fix/657-unbuffered-named-files
Open

Himanshu-singh04 wants to merge 2 commits into
uutils:mainfrom
Himanshu-singh04:fix/657-unbuffered-named-files

Conversation

@Himanshu-singh04

@Himanshu-singh04 Himanshu-singh04 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #657.

-u flushed standard output but left files written by w, W, and s///w buffered until processing ended. NamedWriter now flushes each completed write when unbuffered mode is active. Other writes retain their existing buffering.

Added an integration test that leaves stdin open and checks each named file before EOF. It failed on the original code and passes with this change.

Validation:

  • cargo test (408 unit tests, 365 integration tests; 2 existing ignored)
  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • git diff --check

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.47%. Comparing base (f8e4029) to head (44f1ffd).

Files with missing lines Patch % Lines
src/sed/processor.rs 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #663      +/-   ##
==========================================
+ Coverage   95.43%   95.47%   +0.04%     
==========================================
  Files          14       14              
  Lines        7730     7764      +34     
  Branches      460      461       +1     
==========================================
+ Hits         7377     7413      +36     
+ Misses        352      350       -2     
  Partials        1        1              
Flag Coverage Δ
macos_latest 96.93% <97.56%> (+0.04%) ⬆️
ubuntu_latest 96.86% <97.56%> (+0.04%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread tests/by-util/test_sed.rs Outdated
for script in ["w", "W", "s/a/A/w"] {
let directory = tempfile::tempdir().unwrap();
let path = directory.path().join("output");
let mut child = Command::new(env!("CARGO_BIN_EXE_sed"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please use new_ucmd!() with run_no_wait() like the other tests instead of Command + CARGO_BIN_EXE_sed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test to use new_ucmd!().run_no_wait() with piped stdin in 606e5ac.

Comment thread tests/by-util/test_sed.rs Outdated
use tempfile::NamedTempFile;
use uutests::new_ucmd;

#[test]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move it next to the other -u / w tests, not at the top of the file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the regression test beside the existing file write tests in 606e5ac.

Comment thread src/sed/named_writer.rs Outdated
/// Write String to the file, possibly with a newline, returning errors.
pub fn write_line(&mut self, line: &str, newline: bool) -> UResult<()> {
self.write_line_bytes(line.as_bytes(), newline)
pub fn write_line(&mut self, line: &str, newline: bool, unbuffered: bool) -> UResult<()> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is write_line still used anywhere? if not, could be removed instead of growing a new arg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the call sites; write_line was unused, so I removed it in 606e5ac.

Comment thread src/sed/processor.rs Outdated
writer.borrow_mut().write_line_bytes(
pattern.as_bytes(),
pattern.is_newline_terminated(),
context.unbuffered,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.unbuffered is also forced on when stdout is a terminal (process_all_files), so sed 's/a/b/w out' big in a terminal now flushes out on every line.
GNU only does that with -u. could you please keep the -u flag separate from the tty detection?

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for this PR!
context.unbuffered is also set when stdout is a terminal, so w files now get flushed on every line in interactive runs too; details inline.
please also squash the "Address unbuffered writer review feedback" commit into the main one.

1 similar comment
@sylvestre

Copy link
Copy Markdown
Contributor

thanks for this PR!
context.unbuffered is also set when stdout is a terminal, so w files now get flushed on every line in interactive runs too; details inline.
please also squash the "Address unbuffered writer review feedback" commit into the main one.

@Himanshu-singh04
Himanshu-singh04 force-pushed the fix/657-unbuffered-named-files branch from 606e5ac to 914b153 Compare November 11, 2026 15:21
@codspeed

codspeed Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.86%

2 warnings

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark with a significant change ran in a different software environment

Its base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the change might come from this difference rather than from the code. Open the benchmark to see what changed.

See affected benchmarks

❌ 1 regressed benchmark
✅ 10 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ access_log_translit 953.6 ms 991.9 ms -3.86%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Himanshu-singh04:fix/657-unbuffered-named-files (44f1ffd) with main (f8e4029)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sed - -u does not flush w output files after each line

2 participants