Skip to content

Conversation

@ianic
Copy link
Contributor

@ianic ianic commented Feb 26, 2024

in build.zig.zon.

That allows us to unpack tars which don't have leading root folder. Like
examples from #17779.

Trying to fetch
https://chromium.googlesource.com/chromium/tools/depot_tools.git/+archive/refs/heads/main.tar.gz
with default settings results in error. That archive has files in the root:

$ tar tvf main.tar | head
-rw-r--r-- 0/0            3848 2024-02-26 12:21 .cipd_impl.ps1
-rw-r--r-- 0/0              31 2024-02-26 12:21 .flake8
-rw-r--r-- 0/0            1682 2024-02-26 12:21 .gitattributes
-rw-r--r-- 0/0            2040 2024-02-26 12:21 .gitignore
-rw-r--r-- 0/0             857 2024-02-26 12:21 .isort.cfg
-rw-r--r-- 0/0              48 2024-02-26 12:21 .style.yapf
-rw-r--r-- 0/0            1978 2024-02-26 12:21 .vpython
-rw-r--r-- 0/0            2429 2024-02-26 12:21 .vpython3
-rw-r--r-- 0/0             128 2024-02-26 12:21 BUILD_OWNERS
-rw-r--r-- 0/0             156 2024-02-26 12:21 CROS_OWNERS

stripping one folder (default) results in empty files names.
Setting tar_strip_components = 0 in build.zig.zon enables fetching such
archives.

    .dependencies = .{
        .chromium = .{
            .url = "https://chromium.googlesource.com/chromium/tools/depot_tools.git/+archive/refs/heads/main.tar.gz",
            .hash = "122089fd900653f199701726fe43bf956d9613f2c7ef4e216d363700f5c7df0cb4d8",
            .tar_strip_components = 0,
        },

I'm not a fan of adding endless configuration options. Without configuration we can try with strip_components = 1 and if that fail with strip_components = 0, but I can imagine case where first will pass but right is the second. For example if we tar some source without root but it has inside just single src folder and we don't wont that src folder stripped.

In practice tar_strip_components will have only two values 1 (default) or 0. So it is only needed to set it to 0 in rare cases. Instead of int it could be some bool switch tar_dont_strip... But I keep it like this because shell tar has it same way.

Fixes #17779

Prior to
[this](ziglang@ef9966c#diff-08c935ef8c633bb630641d44230597f1cff5afb0e736d451e2ba5569fa53d915R805)
commit tar was not a valid extension. After that this one is valid case.
in build.zig.zon.

That allows us to unpack tars which don't have leading root folder. Like
examples from ziglang#17779.

Trying to fetch
`https://chromium.googlesource.com/chromium/tools/depot_tools.git/+archive/refs/heads/main.tar.gz`
with default settings results in error. That archive has files in the
root:
```
$ tar tvf main.tar | head
-rw-r--r-- 0/0            3848 2024-02-26 12:21 .cipd_impl.ps1
-rw-r--r-- 0/0              31 2024-02-26 12:21 .flake8
-rw-r--r-- 0/0            1682 2024-02-26 12:21 .gitattributes
-rw-r--r-- 0/0            2040 2024-02-26 12:21 .gitignore
-rw-r--r-- 0/0             857 2024-02-26 12:21 .isort.cfg
-rw-r--r-- 0/0              48 2024-02-26 12:21 .style.yapf
-rw-r--r-- 0/0            1978 2024-02-26 12:21 .vpython
-rw-r--r-- 0/0            2429 2024-02-26 12:21 .vpython3
-rw-r--r-- 0/0             128 2024-02-26 12:21 BUILD_OWNERS
-rw-r--r-- 0/0             156 2024-02-26 12:21 CROS_OWNERS
```

stripping one folder (default) results in empty files names.
Setting tar_strip_components = 0 in build.zig.zon enables fetching such
archives.

```
    .dependencies = .{
        .chromium = .{
            .url = "https://chromium.googlesource.com/chromium/tools/depot_tools.git/+archive/refs/heads/main.tar.gz",
            .hash = "122089fd900653f199701726fe43bf956d9613f2c7ef4e216d363700f5c7df0cb4d8",
            .tar_strip_components = 0,
        },
```
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

Thanks for doing this work.

Note that this is would not be the correct place to put this configuration value, since it applies specifically to the URL, not the package, and it's planned to support multiple URL mirrors per package, which may or may not be tar files. However, instead of introducing the concept of declarative mutations against fetched packages, I'd like to solve this a different way. Namely, when unpacking tar files, fetch logic should determine whether all the files are inside a single directory or not.

If so, proceed according to the status quo logic.
If not, then strip 0 components instead of 1.

In order to avoid redoing work, this likely involves unpacking the tarball into the temp directory while stripping 0 components, and then checking the results before deciding how to proceed.

@ianic
Copy link
Contributor Author

ianic commented Feb 27, 2024

I made follow up PR #19111 with different logic.
Most changes here are not relevant so I made another one.

@ianic ianic closed this Feb 27, 2024
@ianic ianic deleted the package_tar_strip_components branch April 4, 2024 14:30
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.

error: unable to unpack tarball to temporary directory: TarComponentsOutsideStrippedPrefix

2 participants