Skip to content

import-tar: fix nfiles being counted twice for regular files - #10146

Merged
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:claude/charming-bohr-fd92ea
Aug 18, 2026
Merged

import-tar: fix nfiles being counted twice for regular files#10146
ThomasWaldmann merged 1 commit into
borgbackup:masterfrom
ThomasWaldmann:claude/charming-bohr-fd92ea

Conversation

@ThomasWaldmann

Copy link
Copy Markdown
Member

Summary

_import_tar incremented archive.stats.nfiles for every regular tar member, but TarfileObjectProcessors.process_file already counts those in tfo.stats (and process_hardlink counts hardlink members). Since archive.stats += tfo.stats is added before archive.save(), imported archives persisted nfiles = 2 * regular_files + hardlinks into the archive metadata, so borg info / borg repo-list reported a wrong file count for imported archives.

Remove the redundant increment — borg create also relies solely on the processor-side accounting, so import-tar now matches its semantics (each regular file and each hardlink counts once; directories/symlinks/devices/fifos do not).

Test

Added test_import_tar_nfiles: builds a tar via Python's tarfile module (no GNU tar or filesystem hardlink support needed) containing 2 regular files, 1 hardlink member, 1 directory and 1 symlink, imports it, and asserts the archive metadata reports nfiles == 3. Verified the test fails with assert 5 == 3 on the unfixed code.

🤖 Generated with Claude Code

_import_tar incremented archive.stats.nfiles for every regular tar
member, but TarfileObjectProcessors.process_file already counts those
in tfo.stats (and process_hardlink counts hardlink members). Since
archive.stats += tfo.stats is added before archive.save(), imported
archives persisted nfiles = 2 * regular_files + hardlinks.

Remove the redundant increment (borg create also relies solely on the
processor-side accounting) and add a test asserting that the archive
metadata nfiles equals regular files + hardlink members after
borg import-tar.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.95%. Comparing base (9547a53) to head (30194fb).
⚠️ Report is 33 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10146   +/-   ##
=======================================
  Coverage   86.94%   86.95%           
=======================================
  Files         101      101           
  Lines       17984    17983    -1     
  Branches     2737     2737           
=======================================
  Hits        15637    15637           
- Misses       1638     1639    +1     
+ Partials      709      707    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@ThomasWaldmann
ThomasWaldmann merged commit 0baae2a into borgbackup:master Aug 18, 2026
22 of 23 checks passed
@github-actions

Copy link
Copy Markdown

Backport failed for 1.4-maint, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 1.4-maint
git worktree add -d .worktree/backport-10146-to-1.4-maint origin/1.4-maint
cd .worktree/backport-10146-to-1.4-maint
git switch --create backport-10146-to-1.4-maint
git cherry-pick -x 30194fb64f747c0b78900149687d78c213f08b8c

@ThomasWaldmann
ThomasWaldmann deleted the claude/charming-bohr-fd92ea branch August 18, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant