Skip to content

Commit

Permalink
Merge remote-tracking branch 'tango/MAGETWO-53232'
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Melnikov committed Jun 10, 2016
2 parents 931a179 + 5012e39 commit b5c407a
Showing 1 changed file with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,12 @@ public function remove($source, $dest)

// If source doesn't exist, check if it's a glob expression, otherwise we have nothing we can do
if (!file_exists($sourcePath)) {
// Handle globing
$matches = glob($sourcePath);
if ($matches) {
foreach ($matches as $match) {
$newDest = substr($destPath . '/' . basename($match), strlen($this->getDestDir()));
$newDest = ltrim($newDest, ' \\/');
$this->remove(substr($match, strlen($this->getSourceDir())+1), $newDest);
}
return;
}

// Source file isn't a valid file or glob
throw new \ErrorException("Source $sourcePath does not exist");
$this->removeContentOfCategory($sourcePath, $destPath);
return;
} elseif (file_exists($sourcePath) && is_dir($sourcePath)) {
$this->removeContentOfCategory($sourcePath . '/*', $destPath);
@rmdir($destPath);
return;
}

// MP Avoid removing whole folders in case the modman file is not 100% well-written
Expand All @@ -331,6 +324,33 @@ public function remove($source, $dest)
self::rmdirRecursive($destPath);
}

/**
* Search and remove content of category
*
* @param string $sourcePath
* @param string $destPath
* @throws \ErrorException
*/
protected function removeContentOfCategory($sourcePath, $destPath)
{
$sourcePath = preg_replace('#/\*$#', '/{,.}*', $sourcePath);
$matches = glob($sourcePath, GLOB_BRACE);
if ($matches) {
foreach ($matches as $match) {
if (preg_match("#/\.{1,2}$#", $match)) {
continue;
}
$newDest = substr($destPath . '/' . basename($match), strlen($this->getDestDir()));
$newDest = ltrim($newDest, ' \\/');
$this->remove(substr($match, strlen($this->getSourceDir())+1), $newDest);
}
return;
}

// Source file isn't a valid file or glob
throw new \ErrorException("Source $sourcePath does not exist");
}

/**
* Remove an empty directory branch up to $stopDir, or stop at the first non-empty parent.
*
Expand Down

0 comments on commit b5c407a

Please sign in to comment.