Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid nested duplication #183

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/MagentoHackathon/Composer/Magento/Deploystrategy/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand Down