From 91732eee5578d96937c43d70ff5dd16565fcf9f8 Mon Sep 17 00:00:00 2001 From: James Ho Date: Tue, 17 Sep 2019 14:30:31 +0100 Subject: [PATCH] 8330 Correct issue where permission umask of files were not set when archiving in zip format with ZipArchiver --- src/Composer/Package/Archiver/ZipArchiver.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Composer/Package/Archiver/ZipArchiver.php b/src/Composer/Package/Archiver/ZipArchiver.php index 65694cb88..b6cfaf73f 100644 --- a/src/Composer/Package/Archiver/ZipArchiver.php +++ b/src/Composer/Package/Archiver/ZipArchiver.php @@ -45,6 +45,18 @@ class ZipArchiver implements ArchiverInterface } else { $zip->addFile($filepath, $localname); } + + /** + * ZipArchive::setExternalAttributesName is available from >= PHP 5.6 + */ + if (PHP_VERSION_ID >= 50600) { + $perms = fileperms($filepath); + + /** + * Ensure to preserve the permission umasks for the filepath in the archive. + */ + $zip->setExternalAttributesName($localname, ZipArchive::OPSYS_UNIX, $perms << 16); + } } if ($zip->close()) { return $target;