Skip to content

Commit

Permalink
Fix listing directories with trailing / in argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
dillof committed Apr 22, 2024
1 parent 29d89f7 commit d863efe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion regress/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ foreach(FULL_CASE IN LISTS EXTRA_TESTS)
endforeach()

set(XFAIL_TESTS
zipcmp_zip_dir_slash.test
# zipcmp_zip_dir_slash.test
)

foreach(CASE ${XFAIL_TESTS})
Expand Down
5 changes: 2 additions & 3 deletions regress/zipcmp_zip_dir_slash.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ file zipcmp_zip_dir.zip zipcmp_zip_dir.zip
return 1
stdout
--- zipcmp_zip_dir.zip
+++ a
+++ a/
- directory '00-empty-dir/'
- file 'dir-with-file/a', size 1, crc e8b7be43, mtime 0
- directory 'empty-dir/'
+ directory 'dir-with-file/'
+ directory 'empty-dir-in-dir/'
- directory 'empty-dir/'
end-of-inline-data
14 changes: 13 additions & 1 deletion src/zipcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,19 @@ list_directory(const char *name, struct archive *a) {
zip_uint64_t nalloc;
size_t prefix_length;

char *const names[2] = {(char *)name, NULL};
char* normalized_name = strdup(name);
prefix_length = strlen(name) + 1;
while (prefix_length > 0 && normalized_name[prefix_length-1] == '/') {
prefix_length -= 1;
}
if (prefix_length > 0) {
normalized_name[prefix_length] = '\0';
}
else {
normalized_name[1] = '\0';
}

char *const names[2] = {(char *)normalized_name, NULL};


if ((fts = fts_open(names, FTS_NOCHDIR | FTS_LOGICAL, NULL)) == NULL) {
Expand Down

0 comments on commit d863efe

Please sign in to comment.