Skip to content

Commit fe199fb

Browse files
[8.6.0] zipper: handle empty filelist (#28425)
updates the zipper utility so it can handle empty filelists. previously this would fail with ``` File does not seem to exist. ``` (note the double space) rather than being treated as an empty list (`[]`), an empty filelist was being treated as a non-empty list of length one with the only element being an empty string (`['']`) --- Why on earth do I want this? I have a rule that outputs a zip file that may or may not be empty. There is no easy way to tell ahead of time if there will be files. The output *could* be optional, but that would make my life harder for reasons that I can't be bothered explaining (feel free to push on this if it's important). `@bazel_tools//tools/zip:zipper` fails if the filelist is empty and I am working around this by manually creating an empty zip file using the EOCD record: ```js if (files.length === 0) { fs.writeFileSync(zipFile, '\x50\x4b\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'); } ``` it would be nice if I didn't have to do this :) Closes #27008. PiperOrigin-RevId: 812683346 Change-Id: Ifb7dc35b37ce9c07e53786206e90570da542fab7 Commit 349f6fb Co-authored-by: Christian Scott <[email protected]>
1 parent 06431b3 commit fe199fb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

third_party/ijar/test/zip_test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ function test_zipper_permissions() {
211211
fi
212212
}
213213

214+
function test_zipper_empty_file_list() {
215+
local -r LOCAL_TEST_DIR="${TEST_TMPDIR}/${FUNCNAME[0]}"
216+
mkdir -p ${LOCAL_TEST_DIR}/files
217+
touch ${LOCAL_TEST_DIR}/empty_file_list.txt
218+
${ZIPPER} cC ${LOCAL_TEST_DIR}/output.zip @${LOCAL_TEST_DIR}/empty_file_list.txt
219+
}
220+
214221
function test_unzipper_zip64_archive() {
215222
local -r test_dir="${TEST_TMPDIR}/${FUNCNAME[0]}"
216223
mkdir -p "${test_dir}"

third_party/ijar/zip_main.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ char **read_filelist(char *filename) {
248248
return NULL;
249249
}
250250

251+
if (file_stat.total_size == 0) {
252+
char** filelist = static_cast<char**>(malloc(sizeof(char*)));
253+
filelist[0] = NULL;
254+
return filelist;
255+
}
256+
251257
char *data = static_cast<char *>(malloc(file_stat.total_size));
252258
if (!read_file(filename, data, file_stat.total_size)) {
253259
return NULL;

0 commit comments

Comments
 (0)