Skip to content

prelude: Extract exploded_zip symlinks whose directory has no entry - #1673

Closed
phr4nky wants to merge 1 commit into
meta:mainfrom
phr4nky:fix-exploded-zip-symlink-parent-dir
Closed

phr4nky wants to merge 1 commit into
meta:mainfrom
phr4nky:fix-exploded-zip-symlink-parent-dir

Conversation

@phr4nky

@phr4nky phr4nky commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

remote_file(type = "exploded_zip") extracts with prelude/zip_file/tools/unzip.py. The script creates a symlink with os.symlink, which does not create the directory the link is in. That directory exists only if the archive has an entry for it or for a regular file in it. For a directory that holds only symlinks, in an archive without directory entries, the action fails with FileNotFoundError.

This PR creates the directory before the link.

Affected version

origin/main 2099e8f.

Reproduction

mkdir -p src/pkg src/bin && echo x > src/pkg/cli.js && ln -s ../pkg/cli.js src/bin/tool
(cd src && zip -qryD ../a.zip .)
python3 prelude/zip_file/tools/unzip.py --src a.zip --dst out

-D leaves out directory entries; find . -type f -o -type l | zip -qy ../a.zip -@ gives the same archive.

Expected

out/bin/tool is a link to ../pkg/cli.js, as with unzip a.zip -d out.

Actual

FileNotFoundError: [Errno 2] No such file or directory: '../pkg/cli.js' -> 'out/bin/tool'

Test plan

  • prelude/zip_file/tools/tests/test_unzip.py: the new test_a_symlink_in_a_directory_without_an_entry_is_extracted fails with the FileNotFoundError without the change and passes with it. The other four tests pass.
  • Ran the script on archives written by zip -ryD and by zip -y -@ (Info-ZIP 3.0): the link is created and reads through to the file.
  • I ran the script and its unit tests directly with Python 3.14 on macOS, not through a remote_file target.

The `exploded_zip` extractor creates a symlink with `os.symlink`, which does
not create the directory the link is in. That directory exists only if the
archive has an entry for it or for a regular file in it. For a directory that
holds only symlinks, in an archive without directory entries, the action
failed with `FileNotFoundError`.

`zip -ryD` writes such an archive, as does `zip -y -@` with a list of files,
and `unzip` extracts it.

The directory is now created before the link.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2026
@meta-codesync

meta-codesync Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D134892171. (Because this pull request was imported automatically, there will not be any future comments.)

@dtolnay dtolnay left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@meta-codesync meta-codesync Bot closed this in 1fe7822 Nov 28, 2026
@meta-codesync meta-codesync Bot added the Merged label Nov 28, 2026
@meta-codesync

meta-codesync Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 1fe7822.

meta-codesync Bot pushed a commit to meta/buck2-prelude that referenced this pull request Nov 28, 2026
Summary:
`remote_file(type = "exploded_zip")` extracts with `prelude/zip_file/tools/unzip.py`. The script creates a symlink with `os.symlink`, which does not create the directory the link is in. That directory exists only if the archive has an entry for it or for a regular file in it. For a directory that holds only symlinks, in an archive without directory entries, the action fails with `FileNotFoundError`.

This PR creates the directory before the link.

## Affected version

origin/main 2099e8f075.

## Reproduction

```
mkdir -p src/pkg src/bin && echo x > src/pkg/cli.js && ln -s ../pkg/cli.js src/bin/tool
(cd src && zip -qryD ../a.zip .)
python3 prelude/zip_file/tools/unzip.py --src a.zip --dst out
```

`-D` leaves out directory entries; `find . -type f -o -type l | zip -qy ../a.zip -@` gives the same archive.

## Expected

`out/bin/tool` is a link to `../pkg/cli.js`, as with `unzip a.zip -d out`.

## Actual

```
FileNotFoundError: [Errno 2] No such file or directory: '../pkg/cli.js' -> 'out/bin/tool'
```

X-link: meta/buck2#1673

Reviewed By: dtolnay

Differential Revision: D134892171

fbshipit-source-id: da8247f1c4487d24f05361a3a7c2abd8e259ce6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants