Skip to content

Apply path filters to unpacked archive contents - #1745

Draft
zlav wants to merge 4 commits into
masterfrom
unpack-archives-respect-path-filters
Draft

Apply path filters to unpacked archive contents#1745
zlav wants to merge 4 commits into
masterfrom
unpack-archives-respect-path-filters

Conversation

@zlav

@zlav zlav commented Aug 11, 2026

Copy link
Copy Markdown
Member

Overview

--unpack-archives ignored path exclusions: projects inside an archive were analyzed even when the archive sat under an excluded directory.

  • Archives unpack to a temp dir, so applyFiltersToProject evaluated filters against a temp-relative path (maven-project/) that no user filter can name — nothing matched, and the project was analyzed.
  • Making that unmatched case drop the project instead would break --unpack-archives outright, since it would filter out all archive contents.
  • Fix reuses the existing FileAncestry prefix from ANE-895: full origin path for unpack archives #1231 (already threaded through Discovery.Archive.discover for origin path reporting) rather than adding new provenance: applyFiltersToProject now takes that prefix and prepends it, so filters see third-party/lib.zip/maven-project/. The prefix accumulates across nested archives.

The ticket's pointer at decompressFiles path filtering in Core is a red herring for this symptom — the leak is CLI-side, at the filter callsite.

Testing plan

  • 17 new examples in test/App/Fossa/AnalyzeSpec.hs, passing: exclude/include filters on archive contents, nested archives-in-archives, and four covering how the prefix is derived — it must be exactly the archive's path relative to the scan basedir, leaking no ancestor above the basedir and stripping no intermediate directory.
  • Full unit-tests suite: 1432 examples, 27 failures, all pre-existing in untouched modules (Lernie / Themis / Conan) with the same Codec.Compression.Lzma: decoding error from the absent vendor-bins/ binaries in this checkout.

Risks

Behavior change for anyone relying on --unpack-archives to scan archives that sit under an excluded path.

References

  • ANE-2449 — reported via a customer support ticket.

zlav and others added 4 commits August 11, 2026 13:21
Projects discovered inside an archive unpacked by --unpack-archives live
in a temp directory, so filters were evaluated against a path the user
cannot name and exclusions never matched.

Prepend the archive's FileAncestry path prefix — already threaded through
discovery for origin path reporting — to the project's discovered path
before applying filters, so `third-party` excludes projects found inside
`third-party/lib.zip`. The prefix accumulates across nested archives.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Path.Windows.mkAbsDir rejects absolute paths without a drive letter, and
because these are Template Haskell splices it fails at compile time, so
test:unit-tests would not build on Windows.

Follow the repo's existing idiom (see ForkAliasSpec): one CPP-guarded
binding for the filesystem root, with every other path derived from it
via mkRelDir and </>. Relative paths parse identically on both
platforms, so this keeps a single #ifdef in the file rather than one per
test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The existing archive tests hand applyFiltersToProject an already-correct
FileAncestry, so nothing covered the code that produces it: a regression
in ancestryDirect or convertArchiveToDir would leave all of them green.

Pin the invariant that the prefix is exactly the archive's path relative
to the scan basedir. The case that matters is a scan rooted below the
archive's ancestors (basedir <root>/third-party/user, archive at
project/archive.tar): nothing above the basedir may leak in, and no
intermediate directory may be stripped. Filters on third-party or user
must not match, since those directories are invisible to the scan.

These pass against the current implementation; they are regression
guards, not a bug report. Export convertArchiveToDir to test it.

Also fill in the changelog entry with the user-visible behavior change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant