Skip to content

diff: date a missing file at the Unix Epoch with -N - #369

Merged
sylvestre merged 2 commits into
uutils:mainfrom
nurlanmnn:fix-new-file-epoch-361
Nov 10, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
nurlanmnn:fix-new-file-epoch-361

Conversation

@nurlanmnn

Copy link
Copy Markdown
Contributor

Fixes #361.

With -N/--new-file, a missing operand is now dated 1970-01-01 00:00:00 in unified and context headers (including -r) instead of the current time, which is what patch uses to detect file creation and deletion. Added a regression test for -u, -c, both locales, and recursive mode.

This change was written with AI assistance (Codex/Cursor) and I reviewed the diff and ran the checks myself; the implementation is written from the issue description, not derived from GNU source.

🤖 Generated with Claude Code

With -N/--new-file the header of a missing file now shows 1970-01-01 instead of the current time, which is what patch relies on to detect creation and deletion. Covers -u, -c and -r. Fixes uutils#361.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Comment thread src/utils.rs Outdated
.and_then(|m| m.modified())
.unwrap_or(SystemTime::now());
.unwrap_or_else(|error| {
if missing_as_empty && error.kind() == std::io::ErrorKind::NotFound {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

with -N, diff -N -u - file now dates stdin at 1970 too: fs::metadata("-") is NotFound.
could you please only use the epoch when the file really was missing, and add a test with stdin?

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.

Good catch, fixed in e57e23f: the epoch is now used only when the file really was missing, so stdin keeps its current time with -N. Added missing_file_as_empty_keeps_stdin_timestamp, which runs -u and -c with stdin on either side.

Comment thread src/unified_diff.rs Outdated
let from_modified_time = get_modification_time(
&params.from.to_string_lossy(),
TimestampStyle::Iso,
params.missing_file != MissingFile::Error,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same check as in diff.rs and context_diff.rs, could be dedup, no?
diff.rs already knows if the file was missing, it could pass that down

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.

Done: the check now lives only in diff.rs, which sets from_missing/to_missing on the params. The formatters just read them.

Record in compare_files whether an operand was absent instead of inferring
it from fs::metadata in each formatter, so stdin keeps its current time
with -N.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sylvestre
sylvestre merged commit e52f910 into uutils:main Nov 10, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

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.

diff - -N: a missing file is dated "now" instead of the Epoch in -u/-c headers

2 participants