ziglang/zig
262
5.9k
Fork
You've already forked zig
755

std.tar.extract fails on macOS due to case-sensitivity #35549

Open
opened 2026年05月30日 21:21:46 +02:00 by Parker-Hitchcock · 4 comments

Zig Version

0.17.0-dev.607+456b2ec07

Steps to Reproduce, Observed Behavior, and Expected Behavior

I was trying to download MPICH with Zig, and they ship a tarball at their downloads page.

Reproduce & Observe

Running zig fetch --save https://www.mpich.org/static/downloads/5.0.1/mpich-5.0.1.tar.gz yields:

error: unable to unpack tarball
 note: unable to create file 'man/man3/MPI_Offset.3': PathAlreadyExists
 note: unable to create file 'man/man3/MPI_AINT.3': PathAlreadyExists
 note: unable to create file 'man/man3/MPI_Count.3': PathAlreadyExists

Manually inspecting the tarball via tar -tf mpich-5.0.1.tar.gz | grep -i "mpi_offset" yields:

mpich-5.0.1/man/man3/MPI_OFFSET.3
mpich-5.0.1/man/man3/MPI_Offset.3

So there are two files with different capitalizations, and since apfs is case-insensitive, it fails to unpack (file already exists on the createDirAndFile call (tar.zig:622)).

Expected behavior

Using the builtin macos tar utility, the file decompresses silently with the "MPI_Offet.3" file, so likely the last entry in the archive overwrites earlier ones. In fact, tar is perfectly happy overwriting whole directories.
It would be nice if zig fetch worked just like wget + tar does on mac, so I propose adding an exclusive: bool = false field to the ExtactOptions struct and have Fetch.zig set that to true.
Open question: what is the default behavior of tar on Linux?

If that seems like a good course of action I can make a PR.

### Zig Version 0.17.0-dev.607+456b2ec07 ### Steps to Reproduce, Observed Behavior, and Expected Behavior I was trying to download MPICH with Zig, and they ship a tarball at [their downloads page](https://www.mpich.org/downloads/). ### Reproduce & Observe Running `zig fetch --save https://www.mpich.org/static/downloads/5.0.1/mpich-5.0.1.tar.gz` yields: ``` error: unable to unpack tarball note: unable to create file 'man/man3/MPI_Offset.3': PathAlreadyExists note: unable to create file 'man/man3/MPI_AINT.3': PathAlreadyExists note: unable to create file 'man/man3/MPI_Count.3': PathAlreadyExists ``` Manually inspecting the tarball via `tar -tf mpich-5.0.1.tar.gz | grep -i "mpi_offset"` yields: ``` mpich-5.0.1/man/man3/MPI_OFFSET.3 mpich-5.0.1/man/man3/MPI_Offset.3 ``` So there are two files with different capitalizations, and since apfs is case-insensitive, it fails to unpack (file already exists on the `createDirAndFile` call (tar.zig:622)). ### Expected behavior Using the builtin macos `tar` utility, the file decompresses silently with the "MPI_Offet.3" file, so likely the last entry in the archive overwrites earlier ones. In fact, tar is perfectly happy overwriting whole directories. It would be nice if `zig fetch` worked just like `wget` + `tar` does on mac, so I propose adding an `exclusive: bool = false` field to the ExtactOptions struct and have Fetch.zig set that to true. Open question: what is the default behavior of tar on Linux? If that seems like a good course of action I can make a PR.
Contributor
Copy link

AFAIK tar on linux will overwrite file with a file, but not a directory with a file or vice versa.

Missing a man page might not be a deal breaker,
but missing a source file is -- Zig's explicitness helps detect the issue earlier.

Consider the following:
A Zig app developed on a case-sensitive FS,
that has a ./src/Modules.zig and ./src/modules.zig

Overwriting one with the other on a case-insensitive FS will simply result in compilation errors due to missing/mismatched type/field declarations.

AFAIK tar on linux will overwrite file with a file, but not a directory with a file or vice versa. Missing a `man` page might not be a deal breaker, but missing a source file is -- Zig's explicitness helps detect the issue earlier. Consider the following: A Zig app developed on a case-sensitive FS, that has a `./src/Modules.zig` and `./src/modules.zig` Overwriting one with the other on a case-insensitive FS will simply result in compilation errors due to missing/mismatched type/field declarations.

The paths field already exists to solve this problem.

If both files are included by the paths field, then the error is correct.

If one of the files is excluded, then the tar extraction code could be enhanced to apply this filter earlier and avoid the problem because there is no ambiguity.

If this is a "pristine tarball" fetch (i.e. no build.zig.zon file) then this is why it's planned to support the paths field on the "other side" of the fetch URL.

If tar specification says that subsequent files are supposed to overwrite previous ones, then that can be implemented. However I do not believe that is the case. I don't think there even is a specification. Therefore dealing with ambiguity with an error is appropriate.

The `paths` field already exists to solve this problem. If both files are included by the paths field, then the error is correct. If one of the files is excluded, then the tar extraction code could be enhanced to apply this filter earlier and avoid the problem because there is no ambiguity. If this is a "pristine tarball" fetch (i.e. no build.zig.zon file) then this is why it's planned to support the `paths` field on the "other side" of the fetch URL. If tar specification says that subsequent files are supposed to overwrite previous ones, then that can be implemented. However I do not believe that is the case. I don't think there even is a specification. Therefore dealing with ambiguity with an error is appropriate.
Contributor
Copy link

the spec is https://www.gnu.org/software/tar/manual/html_chapter/Tar-Internals.html
also https://pubs.opengroup.org/onlinepubs/9799919799/utilities/pax.html#tag_20_94_13_06
core format is ISO/IEC 9945-1:1990 / IEEE Std 1003.1-1990 §10.1 for Archive/Interchange File Format
transcribed in the page above, which also documents gnu's extensions to it

also https://www.gnu.org/software/tar/manual/html_section/Portability.html

https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?h=v1.35#n1248
https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?h=v1.35#n1175
implementation depends on cli options

 -k, --keep-old-files
 Don't replace existing files when extracting.
 --overwrite
 Overwrite existing files when extracting.
 -U, --unlink-first
 Remove each file prior to extracting over it.
the spec is https://www.gnu.org/software/tar/manual/html_chapter/Tar-Internals.html also https://pubs.opengroup.org/onlinepubs/9799919799/utilities/pax.html#tag_20_94_13_06 core format is ISO/IEC 9945-1:1990 / IEEE Std 1003.1-1990 §10.1 for Archive/Interchange File Format transcribed in the page above, which also documents gnu's extensions to it also https://www.gnu.org/software/tar/manual/html_section/Portability.html https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?h=v1.35#n1248 https://cgit.git.savannah.gnu.org/cgit/tar.git/tree/src/extract.c?h=v1.35#n1175 implementation depends on cli options ``` -k, --keep-old-files Don't replace existing files when extracting. --overwrite Overwrite existing files when extracting. -U, --unlink-first Remove each file prior to extracting over it. ```

Totally makes sense, would definitely want to error out on anything in the source's paths colliding, and thanks for checking that there really isn't a standard.

This is a pristine tarball, so yeah I would love to have the option to add a .paths field to my dependency in build.zig.zon, as that would take care of the error. Is there prior discussion on this? How would that layering go if it the tarball wasn't pristine? I'd expect just the intersection of the two.

Alternative option: add the ability to give pristine tarballs their own manifest, right in your project's build.zig.zon. Could look something like:

.dependencies=.{.mpich=.{.url="https://www.mpich.org/static/downloads/5.0.1/mpich-5.0.1.tar.gz",.hash="hash of just the stuff in paths",.manifest=.{// Must follow build.zig.zon specs, so:.name=.mpich,.version="5.0.1",.fingerprint=0xffffffff,// Reserved for bare so we good.minimum_zig_version="0.0.0",// maybe someone ships a zig tarball w/o zon?.dependencies=.{}// could only be usefull if zig tarball w/o zon, which makes no sense..paths=.{"src/","modules/",...// Everything except man in my case}}}}

For a normal package (with a build.zig.zon), this could either be an error, or just completely overwrite the package's. If we go with the latter, then obviously having dependencies and minimum_zig_version make more sense. Could be a cool mechanic to force an upstream package to use a fork of a dependency or something (at the risk of being kinda redundant).

Totally makes sense, would definitely want to error out on anything in the source's `paths` colliding, and thanks for checking that there really isn't a standard. This is a pristine tarball, so yeah I would love to have the option to add a `.paths` field to my dependency in build.zig.zon, as that would take care of the error. Is there prior discussion on this? How would that layering go if it the tarball wasn't pristine? I'd expect just the intersection of the two. Alternative option: add the ability to give pristine tarballs their own manifest, right in your project's build.zig.zon. Could look something like: ```zig .dependencies = .{ .mpich = .{ .url = "https://www.mpich.org/static/downloads/5.0.1/mpich-5.0.1.tar.gz", .hash = "hash of just the stuff in paths", .manifest = .{ // Must follow build.zig.zon specs, so: .name = .mpich, .version = "5.0.1", .fingerprint = 0xffffffff, // Reserved for bare so we good .minimum_zig_version = "0.0.0", // maybe someone ships a zig tarball w/o zon? .dependencies = .{} // could only be usefull if zig tarball w/o zon, which makes no sense. .paths = .{ "src/", "modules/", ... // Everything except man in my case } } } } ``` For a normal package (with a build.zig.zon), this could either be an error, or just completely overwrite the package's. If we go with the latter, then obviously having dependencies and minimum_zig_version make more sense. Could be a cool mechanic to force an upstream package to use a fork of a dependency or something (at the risk of being kinda redundant).
Sign in to join this conversation.
No Branch/Tag specified
master
elfv2
spork8
restricted
0.16.x
panic-rewrite
parking-futex-lockfree
windows-Io-cleanup
Io-watch
ParseCommandLineOptions
windows-async-files
poll-ring
debug-file-leaks-differently
debug-file-leaks
ProcessPrng
elfv2-dyn
jobserver
threadtheft
io-threaded-no-queue
0.15.x
Io.net
comptime-allocator
restricted-function-pointers
cli
wasm-linker-writer
wrangle-writer-buffering
sha1-stream
async-await-demo
fixes
0.14.x
ast-node-methods
macos-debug-info
make-vs-configure
fuzz-macos
sans-aro
ArrayList-reserve
incr-bug
llvm-ir-nosanitize-metadata
ci-tarballs
ci-scripts
threadpool
0.12.x
new-pkg-hash
json-diagnostics
more-doctests
rework-comptime-mutation
0.11.x
ci-perf-comment
stage2-async
0.10.x
autofix
0.9.x
aro
hcs
0.8.x
0.7.x
0.16.0
0.15.2
0.15.1
0.15.0
0.14.1
0.14.0
0.12.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.1
0.1.0
Labels
Clear labels
abi/f32
abi/ilp32
abi/sf
accepted
This proposal is planned.
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
The web application for interactive documentation and generation of its assets.
backend/c
The C backend outputs C source code.
backend/llvm
The LLVM backend outputs an LLVM bitcode module.
backend/self-hosted
The self-hosted backends produce machine code directly.
binutils
Zig's included binary utilities: zig ar, zig dlltool, zig lib, zig ranlib, zig objcopy, and zig rc.
breaking
Implementing this issue could cause existing code to no longer compile or have different behavior.
build system
The Zig build system - zig build, std.Build, the build runner, and package management.
debug info
An issue related to debug information (e.g. DWARF) produced by the Zig compiler.
docs
An issue with documentation, e.g. the language reference or standard library doc comments.
error message
This issue points out an error message that is unhelpful and should be improved.
frontend
Tokenization, parsing, AstGen, ZonGen, Sema, Legalize, and Liveness.
fuzzing
An issue related to Zig's integrated fuzz testing.
incremental
Reuse of internal compiler state for faster compilation.
lib/c
This issue relates to Zig's libc implementation and/or vendored libcs.
lib/compiler-rt
This issue relates to Zig's compiler-rt library.
lib/cxx
This issue relates to Zig's vendored libc++ and/or libc++abi.
lib/std
This issue relates to Zig's standard library.
lib/tsan
This issue relates to Zig's vendored libtsan.
lib/ubsan-rt
This issue relates to Zig's ubsan-rt library.
lib/unwind
This issue relates to Zig's vendored libunwind.
linking
Zig's integrated object file and incremental linker.
miscompilation
The compiler reports success but produces semantically incorrect code.
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
This issue suggests language modifications. If it also has the "accepted" label then it is planned.
release notes
This issue or pull request should be mentioned in the release notes.
testing
This issue is related to testing the compiler, standard library, or other parts of Zig.
zig cc
Zig as a drop-in C-family compiler.
zig fmt
The Zig source code formatter.
zig reduce
The Zig source code reduction tool.
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
No labels
abi/f32
abi/ilp32
abi/sf
accepted
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
backend/c
backend/llvm
backend/self-hosted
binutils
breaking
build system
debug info
docs
error message
frontend
fuzzing
incremental
lib/c
lib/compiler-rt
lib/cxx
lib/std
lib/tsan
lib/ubsan-rt
lib/unwind
linking
miscompilation
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
release notes
testing
zig cc
zig fmt
zig reduce
bounty
bug
contributor-friendly
downstream
enhancement
infra
optimization
question
regression
upstream
use case
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig#35549
Reference in a new issue
ziglang/zig
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?