Repository navigation
diff: date a missing -N operand at the Epoch in headers - #367
sarankumar1325 wants to merge 3 commits into
Conversation
With -N, a missing operand is treated as empty. GNU dates it at 1970-01-01 00:00:00 in the -u/-c headers, which is how patch knows to create or remove the file. We used the current time for any stat error, so patch left an empty file behind. Use the Epoch when the file does not exist; stdin and other errors keep the current time. Fixes uutils#361
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
| /// Retrieves the modification time of the input file specified by file path. | ||
| /// A file that does not exist (treated as empty with `-N`) is dated at the | ||
| /// Unix Epoch, as GNU diff does, so that `patch` knows to create or delete | ||
| /// it. If any other error occurs, it returns the current system time. |
There was a problem hiding this comment.
could be shorter, no? something like "A missing file (-N) is dated at the Epoch, other errors at now."
| missing.display() | ||
| ))); | ||
| } | ||
| } |
There was a problem hiding this comment.
did you run the upstream testsuite on this?
TESTS=new-file ./tests/run-upstream-testsuite.sh
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
sorry but it needs to be rebased |
Fixes #361
With
-N/--new-file, a missing operand is treated as empty. GNU dates it at the Unix Epoch (1970-01-01 00:00:00) in the unified and context headers. That is the conventionpatchuses to tell that a file must be created or removed.get_modification_timefell back to the current time for any metadata error, so the missing side got today's date andpatchleft an empty file behind instead of deleting it:get_modification_timenow returns the Epoch when the file does not exist (ErrorKind::NotFound). Standard input (-) and other errors keep the current time as before. This covers-u,-c(both timestamp styles) and-r -Ndirectory comparisons, since they all go through this function. Output now matches GNU diff 3.x on the box for all three.Tests:
tests/by-util/test_diff.rs:new_file_missing_side_dated_at_epoch(unix only, since it setsTZlikecontext_timestamp_follows_time_locale) checks-u,-cwith an ISO locale and-cwithLC_ALL=C, with the missing file on either side, plus-r -N -uover two directories. It fails on main and passes with this change.src/utils.rs: theinvalid_fileunit test asserted the old "now" fallback for a missing file. It is replaced bymissing_file(expects the Epoch) andstdin(expects the current time for-).cargo test --test tests(43 passed),cargo test --lib modification_time,cargo fmt --checkandcargo clippy -- -D warningsare clean.I used an AI assistant to write this change. I reviewed and tested it myself.