Skip to content

Commit 705953f

Browse files
committed
Merge pull request #162 from AydinHassan/hotfix/double-slashes-filepath
Hotfix/double slashes filepath
2 parents 495c9fd + 0f99a3e commit 705953f

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

src/MagentoHackathon/Composer/Magento/Deploystrategy/DeploystrategyAbstract.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,33 @@ public function addMapping($key, $value)
291291
$this->mappings[] = array($key, $value);
292292
}
293293

294+
/**
295+
* @param string $path
296+
* @return string
297+
*/
298+
protected function removeLeadingSlash($path)
299+
{
300+
return ltrim($path, '\\/');
301+
}
302+
303+
/**
304+
* @param string $path
305+
* @return string
306+
*/
294307
protected function removeTrailingSlash($path)
295308
{
296309
return rtrim($path, '\\/');
297310
}
298311

312+
/**
313+
* @param string $path
314+
* @return string
315+
*/
316+
protected function removeLeadingAndTrailingSlash($path)
317+
{
318+
return trim($path, '\\/');
319+
}
320+
299321
/**
300322
* Normalize mapping parameters using a glob wildcard.
301323
*
@@ -313,8 +335,8 @@ public function create($source, $dest)
313335
return;
314336
}
315337

316-
$sourcePath = $this->getSourceDir() . '/' . $this->removeTrailingSlash($source);
317-
$destPath = $this->getDestDir() . '/' . $dest;
338+
$sourcePath = $this->getSourceDir() . '/' . $this->removeLeadingSlash($source);
339+
$destPath = $this->getDestDir() . '/' . $this->removeLeadingSlash($dest);
318340

319341
/* List of possible cases, keep around for now, might come in handy again
320342
@@ -350,9 +372,12 @@ public function create($source, $dest)
350372
$matches = glob($sourcePath);
351373
if ($matches) {
352374
foreach ($matches as $match) {
353-
$newDest = substr($destPath . '/' . basename($match), strlen($this->getDestDir()));
354-
$newDest = ltrim($newDest, ' \\/');
355-
$this->create(substr($match, strlen($this->getSourceDir()) + 1), $newDest);
375+
$absolutePath = sprintf('%s/%s', $this->removeTrailingSlash($destPath), basename($match));
376+
$relativeDestination = substr($absolutePath, strlen($this->getDestDir())); //strip off dest dir
377+
$relativeDestination = $this->removeLeadingSlash($relativeDestination);
378+
$relativeSource = substr($match, strlen($this->getSourceDir()) + 1);
379+
380+
$this->create($relativeSource, $relativeDestination);
356381
}
357382
return true;
358383
}

tests/MagentoHackathon/Composer/Magento/Deploystrategy/SymlinkTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,21 @@ public function testDeployedFilesAreStored()
135135
$this->strategy->getDeployedFiles()
136136
);
137137
}
138+
139+
public function testGlobFileResultsDoNotContainDoubleSlashesWhenDestinationDirectoryExists()
140+
{
141+
$this->mkdir(sprintf('%s/app/etc/modules/', $this->sourceDir));
142+
$this->mkdir(sprintf('%s/app/etc/modules', $this->destDir));
143+
touch(sprintf('%s/app/etc/modules/EcomDev_PHPUnit.xml', $this->sourceDir));
144+
touch(sprintf('%s/app/etc/modules/EcomDev_PHPUnitTest.xml', $this->sourceDir));
145+
146+
$this->strategy->create('/app/etc/modules/*.xml', '/app/etc/modules/');
147+
148+
$expected = array(
149+
'/app/etc/modules/EcomDev_PHPUnit.xml',
150+
'/app/etc/modules/EcomDev_PHPUnitTest.xml',
151+
);
152+
153+
$this->assertEquals($expected, $this->strategy->getDeployedFiles());
154+
}
138155
}

0 commit comments

Comments
 (0)