Skip to content

Support streaming TAR hard-link extraction and opt-in preservation - #493

Open
wilx wants to merge 11 commits into
codehaus-plexus:masterfrom
wilx:hardlinks-v2
Open

wilx wants to merge 11 commits into
codehaus-plexus:masterfrom
wilx:hardlinks-v2

Conversation

@wilx

@wilx wilx commented Sep 13, 2026 •

Copy link
Copy Markdown

Adds streaming TAR hard-link extraction, opt-in preservation, and logical alias contents through archived file sets.

  • Normal extraction uses one forward stream. Hard links reference earlier regular members or backward-link chains and use the target's current mapped destination.
  • If a selector excludes the target, an existing on-disk target is used. Genuinely absent targets warn and skip in every failure mode, allowing extraction to continue without creating empty files or replacing existing alias output. Invalid archive relationships, unsafe paths, and non-regular targets remain fatal.
  • Refused native links default to deferred copying (HardLinkFailureMode.COPY_TARGET); FAIL and SKIP are also available. Copies use final on-disk target contents and do not share an inode.
  • TarArchiver.setPreserveHardLinks(true) preserves resources with matching identities and compatible metadata. The default remains false; transformed contents, unknown identities, and conflicting metadata produce full entries.
  • Alias contents support alias-only selection, TAR repacking, and ZIP conversion. Reading earlier payloads may replay decompression and cache requested contents.

TAR creation retains its existing copy-error handling in both preservation modes. Only successfully written entries become hard-link targets. Collections supplied through addResources() remain caller-owned; the archiver closes internally created collections and the streams and closeable iterators it consumes.

Depends on #548, which separates the shared path resolver, directory cache, optional symlink traversal policy, and shared destination-collision behavior for independent review. This branch is rebased onto it. Uses released Plexus IO 3.8.1 and addresses #286.

Local validation on JDK 17/Linux: 873 tests, zero failures/errors, 22 skipped; build, formatting, and Javadoc passed. Windows and macOS execution remain unvalidated.

Documentation

@wilx wilx changed the title Support TAR hard-link extraction and opt-in preservation Support streaming TAR hard-link extraction and opt-in preservation Sep 13, 2026
@wilx
wilx force-pushed the hardlinks-v2 branch 2 times, most recently from edcfad4 to 4b2cc87 Compare September 14, 2026 17:29
@wilx
wilx marked this pull request as ready for review September 14, 2026 17:30
@wilx

wilx commented Sep 26, 2026

Copy link
Copy Markdown
Author

Rebased.

@wilx
wilx marked this pull request as draft September 26, 2026 11:12
@wilx
wilx marked this pull request as ready for review September 26, 2026 13:49
@wilx
wilx marked this pull request as draft September 26, 2026 13:53
@wilx
wilx marked this pull request as ready for review September 26, 2026 14:16
@slachiewicz slachiewicz added the enhancement New feature or request label Oct 29, 2026
@slachiewicz

This comment has been minimized.

@slachiewicz

Copy link
Copy Markdown
Member

Thanks. The hard-link handling holds up: I couldn't make extraction write outside the target (links through outside symlinks, .., links to symlinks, forward references, case-collision swaps), and a failed link leaves no temporary file.

Extraction isn't opt-in, so these behaviour changes reach existing callers:

  1. TarEntryIndex rejects : and \ in hard-link names. A tar with a:b and a link to it extracted on master and now aborts; no test covers this.
  2. A selected link whose target a selector excludes now aborts; master wrote an empty file.
  3. On a file system that refuses hard links, extraction fails, while symlinks fall back to copying the target (COPY_TARGET). Could hard links do the same?
  4. All formats: a regular entry over an existing in-tree symlink now throws "Entry is outside of the target directory", and a directory entry over an existing file throws FileAlreadyExistsException. Master wrote through the link and ignored the file, respectively.
  5. TarArchiver no longer swallows read failures, for every tar rather than only with preservation on.
  6. cleanUp now closes Closeable collections the caller passed to addResources.

About a third of the main change (path resolution, the directory cache, setFailOnSymlinkTraversal) is independent of hard links. Could it move to its own PR? That would be easier to review and to describe in the release notes.

@wilx
wilx marked this pull request as draft November 21, 2026 11:00
@wilx

wilx commented Nov 21, 2026

Copy link
Copy Markdown
Author

I've updated the branch in response to your review:

  1. Removed the blanket colon/backslash restrictions from reading and preservation. Added tests for literal Unix names, caller-supplied name mappings, and resource reads.
  2. A selected hard link now uses the existing mapped target when the archived target is excluded. If the on-disk target is genuinely absent, extraction logs a warning, skips the link, preserves any existing alias output, and continues. This deliberately avoids master's empty-file creation. GNU tar 1.35 and bsdtar 3.8.5 also continue in this case, but report a final failure; this library warns and can return successfully, consistent with the symlink copy fallback's handling of missing targets. Invalid archive relationships, unsafe paths, non-regular targets, and target lookup errors remain fatal.
  3. Added a deferred-copy fallback for refused native hard links, enabled by default, with independent FAIL and SKIP settings. Copies use final target contents, honor overwrite settings, and yield to later successful archive writes.
  4. Separated the path resolver, directory cache, traversal option, and shared destination-collision behavior into Add optional TAR symlink traversal rejection #548. Those behavior changes are retained for independent review. This branch is rebased onto it; once it merges, another rebase will remove that prerequisite from this PR's diff against master.
  5. Restored the original copy-error handling in both preservation modes. Failed entries are excluded from hard-link target registration, while later successful entries can become targets.
  6. Preserved caller ownership of collections passed to addResources(). Only internally created collections are closed; consumed streams and closeable iterators are still closed. Updated the public API documentation and guides.

Added regression coverage for absent targets and dependent links, continuation, existing-output preservation, disappearing or non-regular targets, unsafe mapped paths, and permission-denied lookups.

Local JDK 17/Linux validation passed: 873 tests, zero failures/errors, 22 skipped, plus build, formatting, and Javadoc. Windows and macOS remain unvalidated.

@wilx
wilx marked this pull request as ready for review November 21, 2026 14:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants