From f4c283298febb37631a755d10b89def515f2bd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Thu, 23 Sep 2021 12:16:33 +0100 Subject: [PATCH] Add compatibility fix for Minizip dependency --- cmake/modules/FindMinizip.cmake | 7 +++++++ cmakeconfig.h.in | 3 +++ ui/qt/utils/wireshark_zip_helper.cpp | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmake/modules/FindMinizip.cmake b/cmake/modules/FindMinizip.cmake index 2f81130069..c20062b436 100644 --- a/cmake/modules/FindMinizip.cmake +++ b/cmake/modules/FindMinizip.cmake @@ -43,6 +43,13 @@ if(MINIZIP_FOUND) set(MINIZIP_LIBRARIES ${MINIZIP_LIBRARY}) set(MINIZIP_INCLUDE_DIRS ${MINIZIP_INCLUDE_DIR}) SET(HAVE_MINIZIP ON) + # Some distributions have minizip-ng code instead of the original zlib contrib + # library but keep the old minizip name (because minizip-ng is + # better maintained and provides a compatibility layer). However the + # minizip-ng compatibility layer has some issues. We need to check + # for renamed struct members to avoid an endless game of whack-a-mole. + include(CheckStructHasMember) + check_struct_has_member("zip_fileinfo" "dos_date" "minizip/zip.h" HAVE_MZCOMPAT_DOS_DATE) else() set(MINIZIP_LIBRARIES) set(MINIZIP_INCLUDE_DIRS) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index 7bc92686cb..35b2cad39d 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -130,6 +130,9 @@ /* Define to use the minizip library */ #cmakedefine HAVE_MINIZIP 1 +/* Define if `dos_date' (with underscore) field exists in `zip_fileinfo' */ +#cmakedefine HAVE_MZCOMPAT_DOS_DATE 1 + /* Define to use brotli library */ #cmakedefine HAVE_BROTLI 1 diff --git a/ui/qt/utils/wireshark_zip_helper.cpp b/ui/qt/utils/wireshark_zip_helper.cpp index bcc9f43900..6e78eda64d 100644 --- a/ui/qt/utils/wireshark_zip_helper.cpp +++ b/ui/qt/utils/wireshark_zip_helper.cpp @@ -32,6 +32,14 @@ #include #include +/* Whether we are using minizip-ng and it uses an incompatible 'dos_date' + * struct member. */ +#ifdef HAVE_MZCOMPAT_DOS_DATE +#define _MZDOSDATE dos_date +#else +#define _MZDOSDATE dosDate +#endif + bool WiresharkZipHelper::unzip(QString zipFile, QString directory, bool (*fileCheck)(QString, int), QString (*cleanName)(QString)) { unzFile uf = Q_NULLPTR; @@ -209,7 +217,7 @@ void WiresharkZipHelper::addFileToZip(zipFile zf, QString filepath, QString file memset(&zi, 0, sizeof(zi)); QDateTime fTime = fi.lastModified(); - zi.dosDate = qDateToDosDate(fTime); + zi._MZDOSDATE = qDateToDosDate(fTime); QFile fh(filepath); /* Checks if a large file block has to be written */