Skip to content

uniq: preserve complete lines on read errors - #15361

Open
sunsss123soldier wants to merge 1 commit into
uutils:mainfrom
sunsss123soldier:codex/uniq-preserve-data-on-read-error
Open

sunsss123soldier wants to merge 1 commit into
uutils:mainfrom
sunsss123soldier:codex/uniq-preserve-data-on-read-error

Conversation

@sunsss123soldier

Copy link
Copy Markdown
Contributor

A read error made uniq return before writing its last complete input line. Preserve and flush that output before returning the error, with regression tests covering incomplete records, grouping, and count/filter modes.

Closes #13094.

Keep the pending complete line when a later input read fails, and flush
processed output before returning the read error. Preserve the existing
handling of incomplete records and groups requiring counts or filtering.

Add deterministic regression tests with an injected read failure.
Comment thread src/uu/uniq/src/uniq.rs

if (group_count == 1 && !self.repeats_only) || (group_count > 1 && !self.uniques_only) {
// Counts and filtering require the group to end; a read error does not end it.
if (read_result.is_ok() || !(self.show_counts || self.repeats_only || self.uniques_only))

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.

this condition is hard to read, could you please split it into a named bool?

Comment thread src/uu/uniq/src/uniq.rs
}
}

fn uniq() -> Uniq {

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.

seems like a too generic function name, maybe default_uniq?

Comment thread src/uu/uniq/src/uniq.rs
uniq.repeats_only = true;
check_read_error(&uniq, b"alpha\nalpha\n", b"");
uniq.all_repeated = true;
check_read_error(&uniq, b"alpha\nalpha\n", b"alpha\n");

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.

with -D we print half of the group here, is it really what we want?

This branch has not been deployed

No deployments
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.

bug(uniq): when using /dev/mem it stopped before the end of the file

2 participants