Repository navigation
Conversation
`excludes` of `http_archive` and `extract_archive` matches its regexes against `tar --list` and hands the matched member names to tar through `--exclude-from`. tar reads each line of that file as a glob, so a name with `[`, `*` or `?` excluded other members instead of itself: excluding `pages/[id].js` kept it and dropped `pages/d.js`, with tar exiting 0. Escape the glob characters of each name, which GNU tar and bsdtar both read as the literal character.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D134821702. (Because this pull request was imported automatically, there will not be any future comments.) |
`test_excluded_names_are_read_by_tar_as_globs` pinned the old behavior: excluding `pages/[id].js` kept it and dropped `i.js` and `d.js`. With the names escaped, the excluded file is the one left out. The new `tests/prelude` test covered the same case and goes.
meta-codesync Bot
pushed a commit
to meta/buck2-prelude
that referenced
this pull request
Nov 28, 2026
Summary:
`excludes` of `http_archive` and `extract_archive` matches its regexes against `tar --list`, then writes the matched member names to a file that tar reads with `--exclude-from`. tar reads each line of that file as a glob pattern, not as a name. A member whose name contains `[`, `*` or `?` is not excluded, and other members that the pattern happens to match are dropped instead. tar exits 0, so the build succeeds with the wrong set of files.
Names like that are common in web projects: Next.js, SvelteKit and Astro name route files `[id].js` or `[...slug].tsx`.
This PR escapes `\`, `*`, `?` and `[` in each name it writes to the list. GNU tar and bsdtar both read an escaped character literally.
## Affected version
origin/main 00c2ee4f74. The exclusion list has been written this way since 8af857afa1 ("http_archive: reimplement exclusion lists using dynamic_output").
## Reproduction
```
mkdir -p pages && for f in '[id].js' d.js index.js; do echo x > "pages/$f"; done
tar -czf archive.tar.gz pages
```
```python
extract_archive(
name = "extracted",
src = "archive.tar.gz",
excludes = ["^pages/\\[id\\]\\.js$"],
)
```
`buck2 build :extracted --show-full-simple-output`, then list the output directory.
## Expected
`pages/d.js` and `pages/index.js`.
## Actual
`pages/[id].js` and `pages/index.js`. The exclusion list holds `pages/[id].js`, and tar reads `[id]` as the character class "i or d". Same result with GNU tar 1.35 (Debian) and bsdtar 3.5.3 (macOS).
X-link: meta/buck2#1666
Reviewed By: dtolnay
Differential Revision: D134821702
fbshipit-source-id: 18c7d4ea2335fec790a18a7f1f43ff4d24762b82
Contributor
|
This pull request has been merged in 9ffc7d6. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
excludesofhttp_archiveandextract_archivematches its regexes againsttar --list, then writes the matched member names to a file that tar reads with--exclude-from. tar reads each line of that file as a glob pattern, not as a name. A member whose name contains[,*or?is not excluded, and other members that the pattern happens to match are dropped instead. tar exits 0, so the build succeeds with the wrong set of files.Names like that are common in web projects: Next.js, SvelteKit and Astro name route files
[id].jsor[...slug].tsx.This PR escapes
\,*,?and[in each name it writes to the list. GNU tar and bsdtar both read an escaped character literally.Affected version
origin/main 00c2ee4. The exclusion list has been written this way since 8af857a ("http_archive: reimplement exclusion lists using dynamic_output").
Reproduction
buck2 build :extracted --show-full-simple-output, then list the output directory.Expected
pages/d.jsandpages/index.js.Actual
pages/[id].jsandpages/index.js. The exclusion list holdspages/[id].js, and tar reads[id]as the character class "i or d". Same result with GNU tar 1.35 (Debian) and bsdtar 3.5.3 (macOS).Test plan
tests/e2e/test_prelude_rules.rs:test_excluded_names_are_read_by_tar_as_globspinned the old behavior ([id].jskept,i.jsandd.jsdropped). It is flipped totest_excluded_names_are_matched_literally, which expectsd.js,i.jsandkeep.js; that is what the linux-e2e-tests job reported for this change.[id].jsandindex.js; this branch extractsd.jsandindex.js. A plain exclude ("index") gives the same result as before.d.jsandindex.js.This touches the same file as #1512 (
excludeswithstrip_prefixon bsdtar) but different lines, and fixes a separate problem.