borg icon indicating copy to clipboard operation
borg copied to clipboard

Do not assert on diff if hard link sources are not found due to exclusions

Open cr1901 opened this issue 1 year ago • 1 comments

Per IRC, borg diff will assert if a multiply-linked file is selected for compare, but its hard link source was not selected for compare. Print a warning and allow the diff to continue.

Example failure:

william@xubuntu-dtrain:/shares/wjones/work/browser-hist$ borg diff --content-only ::WD3200BEVT-userprofile-2021-10-17-120019 WD3200BEVT-userprofile-2021-10-24-120006 --pattern="+ pf:" --pattern="+ pp:Downloads" --pattern="! **/" > /dev/null
Local Exception
Traceback (most recent call last):
  File "/home/william/Projects/borg/borg/src/borg/archiver.py", line 5412, in main
    exit_code = archiver.run(args)
  File "/home/william/Projects/borg/borg/src/borg/archiver.py", line 5330, in run
    rc = func(args)
  File "/home/william/Projects/borg/borg/src/borg/archiver.py", line 191, in wrapper
    return method(self, args, repository=repository, **kwargs)
  File "/home/william/Projects/borg/borg/src/borg/archiver.py", line 206, in wrapper
    return method(self, args, repository=repository, manifest=manifest, key=key, archive=archive, **kwargs)
  File "/home/william/Projects/borg/borg/src/borg/archiver.py", line 1172, in do_diff
    for path, diff in diffs:
  File "/home/william/Projects/borg/borg/src/borg/archiver.py", line 1167, in <genexpr>
    diffs = ((path, diff.changes()) for path, diff in diffs if not diff.equal)
  File "/home/william/Projects/borg/borg/src/borg/archive.py", line 1120, in compare_archives_iter
    assert hardlink_master_seen(item1)
AssertionError

Platform: Linux xubuntu-dtrain 5.15.0-112-generic #122-Ubuntu SMP Thu May 23 07:48:21 UTC 2024 x86_64
Linux: Unknown Linux
Borg: 1.4.1.dev26+gad502848  Python: CPython 3.10.12 msgpack: 1.0.8 fuse: pyfuse3 3.2.0 [pyfuse3,llfuse]
PID: 3004014  CWD: /shares/wjones/work/browser-hist
sys.argv: ['/home/william/.local/bin/borg', 'diff', '--content-only', '::WD3200BEVT-userprofile-2021-10-17-120019', 'WD3200BEVT-userprofile-2021-10-24-120006', '--pattern=+ pf:', '--pattern=+ pp:Downloads', '--pattern=! **/']
SSH_ORIGINAL_COMMAND: None

cr1901 avatar Aug 26 '24 19:08 cr1901

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 82.51%. Comparing base (938e144) to head (2720331). Report is 14 commits behind head on 1.4-maint.

Files with missing lines Patch % Lines
src/borg/archive.py 66.66% 1 Missing and 2 partials :warning:
Additional details and impacted files
@@              Coverage Diff              @@
##           1.4-maint    #8344      +/-   ##
=============================================
- Coverage      82.73%   82.51%   -0.23%     
=============================================
  Files             38       38              
  Lines          11049    11081      +32     
  Branches        2123     2133      +10     
=============================================
+ Hits            9141     9143       +2     
- Misses          1344     1369      +25     
- Partials         564      569       +5     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Aug 26 '24 19:08 codecov-commenter

@cr1901 Is this still on your radar?

ThomasWaldmann avatar Sep 28 '24 21:09 ThomasWaldmann

Yes, it's still on my radar. Though, I've been working on trying to finish several things this past month, and am coming around to the PRs I owe you.

cr1901 avatar Sep 28 '24 22:09 cr1901

@ThomasWaldmann Addressed your feedback and added a test. I am marking as ready for review.

cr1901 avatar Oct 02 '24 04:10 cr1901

Thanks! master branch needs checking, the hardlinks stuff is different (better) there.

ThomasWaldmann avatar Oct 06 '24 12:10 ThomasWaldmann

@cr1901 can you help porting this to master branch?

ThomasWaldmann avatar Apr 19 '25 19:04 ThomasWaldmann

@ThomasWaldmann Right now/today, I don't quite have the bandwidth. Ping me again in about a week or so.

cr1901 avatar Apr 19 '25 20:04 cr1901

ping @cr1901 :-)

ThomasWaldmann avatar Apr 29 '25 18:04 ThomasWaldmann

Okay I finally took a peek... looks like you rewrote the hardlink logic for diffs in borg 2? So that using the logic of this PR does not apply cleanly? Specifically, where did the equivalent of this highlighted code go? And how should I go about incorporating it into compare_archives_iter?

cr1901 avatar May 16 '25 00:05 cr1901

@cr1901 thanks for looking into this!

From what I remember:

  • there is a HardlinkManager (or so) class somewhere.
  • hardlinks are now much easier to deal with. all hardlinked items have the identical chunks list and the identical hlid, so it is totally symmetric now (no hl master/slave items anymore).

ThomasWaldmann avatar May 16 '25 07:05 ThomasWaldmann