From c2c3e7b4567a8727bea61e623680e4884157c885 Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Tue, 27 Sep 2016 16:28:48 +0300 Subject: [PATCH 1/7] MAGETWO-51598: bin/magento is installed without execute bit set --- .../Composer/Magento/Plugin.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/MagentoHackathon/Composer/Magento/Plugin.php b/src/MagentoHackathon/Composer/Magento/Plugin.php index ec845f72..8979fb83 100644 --- a/src/MagentoHackathon/Composer/Magento/Plugin.php +++ b/src/MagentoHackathon/Composer/Magento/Plugin.php @@ -157,8 +157,36 @@ public function onNewCodeEvent(\Composer\Script\Event $event) $this->deployLibraries(); $this->saveVendorDirPath($event->getComposer()); $this->requestRegeneration(); + $this->setFilesPermissions(); } + /** + * Set permissions for files using extra->chmod from composer.json + * + * @return void + */ + protected function setFilesPermissions() + { + $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(); + + foreach ($packages as $package) { + $extra = $package->getExtra(); + if (!isset($extra['chmod']) || !is_array($extra['chmod'])) { + continue; + } + + foreach ($extra['chmod'] as $chmod) { + if (!isset($chmod[0]) || !isset($chmod[1]) || strpos($chmod[1], '..') !== false) { + continue; + } + + $file = $this->installer->getTargetDir() . '/' . $chmod[1]; + if (file_exists($file)) { + chmod($file, octdec($chmod[0])); + } + } + } + } protected function deployLibraries() { From 61d7f3bc42321d5cd72bdb7da60e1e9ed0974a39 Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Fri, 30 Sep 2016 11:45:58 +0300 Subject: [PATCH 2/7] MAGETWO-51598: bin/magento is installed without execute bit set --- .../Composer/Magento/Plugin.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/MagentoHackathon/Composer/Magento/Plugin.php b/src/MagentoHackathon/Composer/Magento/Plugin.php index 8979fb83..d97d7ce5 100644 --- a/src/MagentoHackathon/Composer/Magento/Plugin.php +++ b/src/MagentoHackathon/Composer/Magento/Plugin.php @@ -165,26 +165,41 @@ public function onNewCodeEvent(\Composer\Script\Event $event) * * @return void */ - protected function setFilesPermissions() + private function setFilesPermissions() { $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(); foreach ($packages as $package) { + $message = 'Check "chmod" section in composer.json of ' . $package->getName() . ' package.'; $extra = $package->getExtra(); if (!isset($extra['chmod']) || !is_array($extra['chmod'])) { continue; } + $error = false; foreach ($extra['chmod'] as $chmod) { - if (!isset($chmod[0]) || !isset($chmod[1]) || strpos($chmod[1], '..') !== false) { + if (!isset($chmod['mask']) || !isset($chmod['path']) || strpos($chmod['path'], '..') !== false) { + $error = true; continue; } - $file = $this->installer->getTargetDir() . '/' . $chmod[1]; + $file = $this->installer->getTargetDir() . '/' . $chmod['path']; if (file_exists($file)) { - chmod($file, octdec($chmod[0])); + chmod($file, octdec($chmod['mask'])); + } else { + $this->io->writeError([ + 'File doesn\'t exist: ' . $chmod['path'], + $message + ]); } } + + if ($error) { + $this->io->writeError([ + 'Incorrect mask or file path.', + $message + ]); + } } } From 481f7a0fd505fbe847c2ca5549ff204abe4ef9cf Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Fri, 30 Sep 2016 14:19:21 +0300 Subject: [PATCH 3/7] MAGETWO-51598: bin/magento is installed without execute bit set --- README.md | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e8d47b71..439b5f26 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,12 @@ In the component's `composer.json`, specify: * `type`, type of Magento 2 component. * `extra/map`, list of files to move and their paths relative to the Magento root directory. +* `extra/chmod`, list of permissions of files that should be set. + + **Note**: + * `extra/map` is required only if your component needs to be moved to a location other than `/vendor`. Otherwise, omit this section. + * `extra/chmod` is required only if you need to set specific permissions for files. - **Note**: `extra/map` is required only if your component needs to be moved to a location other than `/vendor`. Otherwise, omit this section. ## Supported Components The following list explains the use of `type` in `composer.json`. @@ -165,5 +169,40 @@ The Magneto Composer Installer uses the `copy` deployment strategy. It copies ea There are [other deployment strategies](https://github.com/magento/magento-composer-installer/blob/master/doc/Deploy.md) that could be used; however, we don't guarantee that any of them will work. +## Usage `extra/chmod` + +The following example shows how you can set specific permissions for files. + +Example: + +``` +{ + "name": "magento/module-sample", + "description": "N/A", + "require": { + ... + }, + "type": "magento2-module", + "extra": { + "chmod": [ + { + "mask": "0755", + "path": "bin/magento" + }, + { + "mask": "0644", + "path": "some_dir/file.jpg" + } + ] + } +} +``` + +`mask` is bit mask for chmod command + +`path` is path to file: `/` + +For example: `some_dir/file.jpg` + # Notes - The extra->magento-root-dir option is no longer supported. It displays only to preseve backward compatibility. \ No newline at end of file From f703570a8f425c942a66255699e3a9e04a431cee Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Fri, 30 Sep 2016 14:42:10 +0300 Subject: [PATCH 4/7] MAGETWO-51598: bin/magento is installed without execute bit set --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 439b5f26..fc325cce 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ In the component's `composer.json`, specify: * `type`, type of Magento 2 component. * `extra/map`, list of files to move and their paths relative to the Magento root directory. -* `extra/chmod`, list of permissions of files that should be set. +* `extra/chmod`, list of permissions that should be set for files. **Note**: * `extra/map` is required only if your component needs to be moved to a location other than `/vendor`. Otherwise, omit this section. @@ -175,7 +175,7 @@ The following example shows how you can set specific permissions for files. Example: -``` +```json { "name": "magento/module-sample", "description": "N/A", @@ -198,11 +198,11 @@ Example: } ``` -`mask` is bit mask for chmod command +`mask` is a bit mask for chmod command -`path` is path to file: `/` +`path` is a path to file: `/` -For example: `some_dir/file.jpg` +For example: `/some_dir/file.jpg` # Notes - The extra->magento-root-dir option is no longer supported. It displays only to preseve backward compatibility. \ No newline at end of file From 06ce0524a73411aa12f19bf024b8a314c8cf3bc4 Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Fri, 30 Sep 2016 14:48:28 +0300 Subject: [PATCH 5/7] MAGETWO-51598: bin/magento is installed without execute bit set --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index fc325cce..be3c4480 100644 --- a/README.md +++ b/README.md @@ -200,9 +200,7 @@ Example: `mask` is a bit mask for chmod command -`path` is a path to file: `/` - -For example: `/some_dir/file.jpg` +`path` is a path to file relative to the Magento root folder # Notes - The extra->magento-root-dir option is no longer supported. It displays only to preseve backward compatibility. \ No newline at end of file From 6072a6d5f8218e34bae25325519c6fdfa201606f Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Tue, 4 Oct 2016 14:49:09 +0300 Subject: [PATCH 6/7] MAGETWO-51598: bin/magento is installed without execute bit set --- src/MagentoHackathon/Composer/Magento/Plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MagentoHackathon/Composer/Magento/Plugin.php b/src/MagentoHackathon/Composer/Magento/Plugin.php index d97d7ce5..99f07fb6 100644 --- a/src/MagentoHackathon/Composer/Magento/Plugin.php +++ b/src/MagentoHackathon/Composer/Magento/Plugin.php @@ -157,7 +157,7 @@ public function onNewCodeEvent(\Composer\Script\Event $event) $this->deployLibraries(); $this->saveVendorDirPath($event->getComposer()); $this->requestRegeneration(); - $this->setFilesPermissions(); + $this->setFilePermissions(); } /** @@ -165,7 +165,7 @@ public function onNewCodeEvent(\Composer\Script\Event $event) * * @return void */ - private function setFilesPermissions() + private function setFilePermissions() { $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(); From b903315696f4c49b6fea6a996488ee400ad2b102 Mon Sep 17 00:00:00 2001 From: Bohdan Korablov Date: Tue, 4 Oct 2016 15:19:04 +0300 Subject: [PATCH 7/7] MAGETWO-51598: bin/magento is installed without execute bit set --- src/MagentoHackathon/Composer/Magento/Plugin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MagentoHackathon/Composer/Magento/Plugin.php b/src/MagentoHackathon/Composer/Magento/Plugin.php index 99f07fb6..234bdb50 100644 --- a/src/MagentoHackathon/Composer/Magento/Plugin.php +++ b/src/MagentoHackathon/Composer/Magento/Plugin.php @@ -168,9 +168,9 @@ public function onNewCodeEvent(\Composer\Script\Event $event) private function setFilePermissions() { $packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages(); + $message = 'Check "chmod" section in composer.json of %s package.'; foreach ($packages as $package) { - $message = 'Check "chmod" section in composer.json of ' . $package->getName() . ' package.'; $extra = $package->getExtra(); if (!isset($extra['chmod']) || !is_array($extra['chmod'])) { continue; @@ -189,7 +189,7 @@ private function setFilePermissions() } else { $this->io->writeError([ 'File doesn\'t exist: ' . $chmod['path'], - $message + sprintf($message, $package->getName()) ]); } } @@ -197,7 +197,7 @@ private function setFilePermissions() if ($error) { $this->io->writeError([ 'Incorrect mask or file path.', - $message + sprintf($message, $package->getName()) ]); } }