Skip to content

prelude: Extract exploded_zip files that are in a read-only directory - #1672

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

phr4nky wants to merge 1 commit into
meta:mainfrom
phr4nky:fix-exploded-zip-read-only-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 gives an entry its mode from the archive when the mode has the owner's execute bit. That is true of nearly every directory, so a directory gets its mode as soon as its own entry is extracted. If the mode has no write bit, the files in the directory, which come later in the archive, cannot be created, and the action fails with PermissionError.

This PR records the modes of directories and applies them after everything is extracted, the deepest first.

Affected version

origin/main 2099e8f.

Reproduction

mkdir -p src/ro && echo x > src/ro/f && chmod 555 src/ro
(cd src && zip -qry ../a.zip .)
python3 prelude/zip_file/tools/unzip.py --src a.zip --dst out

ditto -c -k src a.zip on macOS writes the same directory mode.

Expected

out/ro/f is extracted and out/ro is r-xr-xr-x, as with unzip a.zip -d out.

Actual

PermissionError: [Errno 13] Permission denied: 'out/ro/f'

Test plan

  • prelude/zip_file/tools/tests/test_unzip.py: the new test_a_file_in_a_read_only_directory_is_extracted fails with the PermissionError without the change and passes with it. The other four tests pass.
  • Ran the script on archives of the tree above written by zip -ry (Info-ZIP 3.0) and by ditto -c -k (macOS): the file is extracted and the directory is r-xr-xr-x.
  • 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 gives an entry its mode from the archive when
the mode has the owner's execute bit. That is true of nearly every directory,
so a directory got its mode as soon as its own entry was extracted. If the
mode has no write bit, the files in the directory, which come later in the
archive, could not be created, and the action failed with `PermissionError`.

`zip -r` and `ditto -c -k` store such a mode for a directory that is
`r-xr-xr-x` on disk, and `unzip` extracts the result.

Directories now get their mode after everything is extracted, the deepest
first.
@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 D134892160. (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 1481e28 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 1481e28.

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 gives an entry its mode from the archive when the mode has the owner's execute bit. That is true of nearly every directory, so a directory gets its mode as soon as its own entry is extracted. If the mode has no write bit, the files in the directory, which come later in the archive, cannot be created, and the action fails with `PermissionError`.

This PR records the modes of directories and applies them after everything is extracted, the deepest first.

## Affected version

origin/main 2099e8f075.

## Reproduction

```
mkdir -p src/ro && echo x > src/ro/f && chmod 555 src/ro
(cd src && zip -qry ../a.zip .)
python3 prelude/zip_file/tools/unzip.py --src a.zip --dst out
```

`ditto -c -k src a.zip` on macOS writes the same directory mode.

## Expected

`out/ro/f` is extracted and `out/ro` is `r-xr-xr-x`, as with `unzip a.zip -d out`.

## Actual

```
PermissionError: [Errno 13] Permission denied: 'out/ro/f'
```

X-link: meta/buck2#1672

Reviewed By: dtolnay

Differential Revision: D134892160

fbshipit-source-id: f6981fd340bd018b3b751ef77f83b567580252ec
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