From 4237c6d9307ce600ae867c7de4aced6eb467a505 Mon Sep 17 00:00:00 2001 From: Karoly Nemethy Date: Fri, 25 Oct 2019 03:19:56 +0200 Subject: [PATCH 1/2] Avoid nested duplication if a module folder exists when using copy strategy --- .../Composer/Magento/Deploystrategy/Copy.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/MagentoHackathon/Composer/Magento/Deploystrategy/Copy.php b/src/MagentoHackathon/Composer/Magento/Deploystrategy/Copy.php index 2e7ad217..d836ad08 100644 --- a/src/MagentoHackathon/Composer/Magento/Deploystrategy/Copy.php +++ b/src/MagentoHackathon/Composer/Magento/Deploystrategy/Copy.php @@ -28,6 +28,9 @@ public function createDelegate($source, $dest) $sourcePath = $this->getSourceDir() . '/' . $this->removeTrailingSlash($source); $destPath = $this->getDestDir() . '/' . $this->removeTrailingSlash($dest); + if ($this->isForced() && strcasecmp($source, $cleanDest) === 0 && is_dir($destPath) && !$this->deleteDir($destPath)) { + throw new \ErrorException("Destination $destPath exists and could not delete."); + } // Create all directories up to one below the target if they don't exist $destDir = dirname($destPath); @@ -120,6 +123,19 @@ public function createDelegate($source, $dest) return true; } + protected function deleteDir($path) + { + if (!is_dir($path)) { + throw new \ErrorException("Path {$path} is not a directory"); + } + $items = array_diff(scandir($path), array('.', '..')); + foreach ($items as $item) { + $itemPath = $path . DIRECTORY_SEPARATOR . $item; + is_dir($itemPath) ? $this->deleteDir($itemPath) : unlink($itemPath); + } + return rmdir($path); + } + /** * transfer by copy files * From fbf7590459382aef0b2477dfa5040664b38ada53 Mon Sep 17 00:00:00 2001 From: olythy Date: Fri, 25 Oct 2019 03:26:23 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md Avoid nested duplication if a module folder exists when using copy strategy --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cedc990..189e9e7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] +- Avoid nested duplication if a module folder exists when using copy strategy - -- +- ## [3.0.7] - 2016-08-29 - Fixed an issue where symlinks were follwed when removing a module, causing files in vendor to be removed