@bazel_tools//tools/zip:zipper replaces zip contents instead of adding
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the problem:
Bazel's zipper tool, `@bazel_tools//tools/zip:zipper` has a `c` subcommand that is documented as adding files to the archive, presumably creating the archive if needed. Instead, it seems to delete all existing entries in the archive before adding the new ones.
[Documented in [source](https://github.com/bazelbuild/bazel/blob/c0f0f8df62ec7e0aef37846be82ee34f562230c2/third_party/ijar/zip_main.cc), https://github.com/bazelbuild/bazel/issues/2414, [SO](https://stackoverflow.com/questions/57914937/how-do-i-zip-files-in-bazel), presumably intended to be parallel to [zip's add](https://linux.die.net/man/1/zip).]
> c create - add files to x.zip
This happens whether or not the C compression option is specified.
Offhand, it seems like the documented behavior is the more useful one. That's because creating entries encompasses creating from scratch, which would imply that'd it'd be better to fix the implementation than to change the documentation to match. But maybe it's important that zipper delete existing entries if Bazel doesn't clean up old build artifacts?
### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Grab `@bazel_tools//tools/zip:zipper`, and then try running:
```
touch A
zipper c test.zip A
zipinfo test.zip
touch B
zipper c test.zip B
zipinfo test.zip
```
And you'll find that A has been deleted from the archive by the addition of B, contrary to the docs.
(I'd have phrased this in terms of `bazel run @bazel_tools//tools/zip:zipper --` commands, but I couldn't quickly figure out how to run it that way. You get warned that "@bazel_tools//tools/zip:zipper: Not executable." Though clearly it's designed to be run--I'd encountered this in the middle of running it as part of writing a custom rule. If anyone knows how to make the example more minimal that way, would love to hear it.)
### What operating system are you running Bazel on?
macOS 11.4
### What's the output of `bazel info release`?
4.1.0
Contributor guide
Research direction
Start with third_party/ijar/zip_main.cc and reproduce the documented commands using zipper, creating an archive with A and then adding B. Trace the c subcommand's handling of an existing archive. Done means adding B preserves A, matching the documented behavior, with the reproduction or relevant project checks passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100