Categories: C, Cygwin

Testing Info-ZIP

After figuring out how to build the Info-ZIP sources, I had a few commands to test the zip file by creating a few text files to zip.

zip -h > help.txt
zip -h2 > help2.txt
zip -L > license.txt

Unfortunately, the zip -qru ./files.zip -i *.txt command from the OpenJDK is not what we need. To actually create a zip file, use only the -u flag

zip -u files.zip *.txt

To test that the files were zipped successfully, unzip the files and compare them to the original files. Here’s the whole script for this:

echo "---Creating temp directory---"
mkdir temp; cd temp

echo "---Creating text files---"
zip -h > help.txt
zip -h2 > help2.txt
zip -L > license.txt

echo "---Adding text files to a new repo---"
git init
git add *.txt
git commit -m "Add original text files"

echo "---Zipping text files---"
zip -u files.zip *.txt

echo "---Removing text files---"
rm *.txt

echo "---Unzipping text files---"
unzip files.zip

echo "---Checking unzipped files---"
git diff

When using the zip binary for Windows, something strange happens when running the zip command a 2nd time:

$ zip -u files.zip *.txt
        zip warning: files.zip not found or empty
  adding: help.txt (176 bytes security) (deflated 49%)
  adding: help2.txt (176 bytes security) (deflated 62%)
  adding: license.txt (176 bytes security) (deflated 54%)

$ zip -u files.zip *.txt
        zip warning: expected 3 entries but found 0

zip error: Zip file structure invalid (files.zip)

Info-ZIP supports a -sd flag that shows diagnostic information while it runs. It reveals that something is going wrong when reading the archive.

$ zip -usd files.zip *.txt
sd: Zipfile name 'files.zip'
sd: Command line read
sd: Reading archive
        zip warning: expected 3 entries but found 0

zip error: Zip file structure invalid (files.zip)

This is filed as Running zip twice fails with invalid file structure error · Issue #35 · swesonga/Info-ZIP (github.com). Observe that this doesn’t happen when using the original zip binary that shipped with Cygwin:

$ zip.original -usd files.zip *.txt
sd: Zipfile name 'files.zip'
sd: Command line read
sd: Reading archive
sd: Scanning files
sd: Applying filters
sd: Checking dups
sd: Scanning files to update
sd: fcount = 0

Why is this bug only in the Windows build?

Article info




Leave a Reply

Your email address will not be published. Required fields are marked *