From e08143de4b38d83e7928180fcb96b54c29555bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=92=E1=85=A7=E1=86=AB?= =?UTF-8?q?=E1=84=8B=E1=85=AE?= Date: Wed, 3 Aug 2022 18:41:58 +0900 Subject: [PATCH] Fix macOS .dylib symlink issue Uses somewhat herustic method to auto-apply symlink to stale files. Also, some .dylib are not labeled as executable on the zip file, so adding executable bits manually. Fixes #65 --- src/archives/zipextractor.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/archives/zipextractor.cpp b/src/archives/zipextractor.cpp index 3c125c2..4b10c4f 100644 --- a/src/archives/zipextractor.cpp +++ b/src/archives/zipextractor.cpp @@ -16,6 +16,27 @@ static inline QFile::Permissions getPermissionsFromUnix(quint16 type) { return static_cast(((type & 0700) << 6) | ((type & 0700) << 2) | ((type & 0070) << 1) | (type & 0007)); } +static void handleSymlinkDylib(const QString& filename) { + if (filename.endsWith(".dylib")) { + QFile file(filename); + file.open(QFile::ReadOnly); + if (file.size() < 100) { + auto targetFilename = static_cast(file.readLine()); + file.close(); + file.remove(); + QFile::link(targetFilename, filename); + } else { + file.close(); + file.setPermissions( + file.permissions() | + QFileDevice::ExeOwner | + QFileDevice::ExeGroup | + QFileDevice::ExeOther + ); + } + } +} + bool extractZip(QIODevice *in, QDir extractLoc) { in->open(QIODevice::ReadOnly); QDataStream stream(in); @@ -78,6 +99,8 @@ bool extractZip(QIODevice *in, QDir extractLoc) { } file.close(); + + handleSymlinkDylib(extractLoc.filePath(name)); if (rcrc != crc) return false; // CRC-32 Mismatch } else { // Standard DEFLATE @@ -118,6 +141,9 @@ bool extractZip(QIODevice *in, QDir extractLoc) { } file.close(); + + handleSymlinkDylib(extractLoc.filePath(name)); + ret ^= 1; ret |= inflateEnd(&strm); if (ret != Z_OK) return false;