Skip to content

fix: show microsecond precision in borg diff when timestamps differ only at sub-second level (fixes #9147)#9561

Open
hiepau1231 wants to merge 6 commits intoborgbackup:masterfrom
hiepau1231:fix/bsd-hardlink-diff-timestamp-9147
Open

fix: show microsecond precision in borg diff when timestamps differ only at sub-second level (fixes #9147)#9561
hiepau1231 wants to merge 6 commits intoborgbackup:masterfrom
hiepau1231:fix/bsd-hardlink-diff-timestamp-9147

Conversation

@hiepau1231
Copy link
Copy Markdown

@hiepau1231 hiepau1231 commented Apr 5, 2026

Summary

Fixes #9147borg diff on FreeBSD/NetBSD shows confusing [ctime: Wed, 2025-11-05 17:45:53 +0000 -> Wed, 2025-11-05 17:45:53 +0000] output where both timestamps look identical but actually differ at nanosecond level.

  • Add format_timestamp_pair(ts1, ts2) in helpers/time.py: selects second-precision format normally, but upgrades to microsecond precision (%H:%M:%S.%f) when two timestamps appear equal at second resolution but differ at sub-second level
  • Update DiffFormatter.format_time() in helpers/parseformat.py to use format_timestamp_pair(), so diff output shows [ctime: ...17:45:53.000123 ... -> ...17:45:53.000456 ...] instead of the confusing identical-looking pair
  • Re-enable test_hard_link_deletion_and_replacement on FreeBSD, NetBSD, and OpenBSD (was previously skipped): the test now accepts a POSIX-valid sub-second ctime update on surviving hardlinks while verifying no content/mode/mtime changes occurred

Root cause

On BSD, creating a new file at a previously hard-linked path causes a sub-second ctime update on surviving hard links (POSIX-valid behaviour). The old format_time() always used second-precision format, so two timestamps like 17:45:53.000123 and 17:45:53.000456 both rendered as 17:45:53, producing the confusing X -> X output.

Test plan

  • test_format_timestamp_pair_different_seconds — second-precision when timestamps differ by ≥1s
  • test_format_timestamp_pair_same_second_different_microsecond — microsecond-precision for sub-second diff
  • test_format_timestamp_pair_identical — second-precision for identical timestamps
  • test_diff_formatter_format_time_shows_microseconds_when_same_second — full formatter path
  • test_diff_formatter_format_time_no_microseconds_for_different_seconds — control case
  • test_hard_link_deletion_and_replacement on FreeBSD/NetBSD/OpenBSD CI — required before merge

⚠️ The BSD-specific fix can only be validated on FreeBSD/NetBSD/OpenBSD CI runners. All Linux tests pass locally.

hiepau1231 and others added 6 commits April 5, 2026 14:25
… display

Add format_timestamp_pair() function that intelligently formats two timestamps
for diff output. When timestamps are equal at second resolution but differ at
the microsecond level (common on FreeBSD/NetBSD), microsecond precision is used
to show the difference. Otherwise, second-precision format is used to match
existing behavior.

Includes 3 comprehensive unit tests covering:
1. Timestamps differing at second level (no microseconds shown)
2. Timestamps identical at second level but different at microsecond level (microseconds shown)
3. Completely identical timestamps (no microseconds shown)

Fixes issue borgbackup#9147 where diff output showed confusing identical timestamps.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…econd timestamp diffs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BSD may produce a POSIX-valid sub-second ctime change on b/hardlink when
a previously hard-linked path is recreated as a new inode. The test now
accepts this BSD behavior while still verifying no content/mode/mtime changes.

Fixes borgbackup#9147

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ThomasWaldmann
Copy link
Copy Markdown
Member

Thanks for the PR!

That variable formatting is a mixed blessing:

  • for human readers, it might be the best way
  • for automated parsing, it is the worst if the format is not constant

Can you fix the linting issues, so the BSD tests are not cancelled?

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.

freebsd test failure in test_hard_link_deletion_and_replacement

2 participants