Skip to content

Commit

Permalink
Merge pull request #21 from AydinHassan/broken-links
Browse files Browse the repository at this point in the history
Throw exception if broken link is present where directory should be
  • Loading branch information
AydinHassan committed Sep 7, 2015
2 parents cde16a5 + 738458a commit 0c75cef
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ php:
- 5.6
- hhvm

matrix:
allow_failures:
- php: hhvm

install:
- composer self-update
- composer install --prefer-source
Expand Down
14 changes: 13 additions & 1 deletion src/CoreInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AydinHassan\MagentoCoreComposerInstaller;

use Composer\Util\Filesystem;
use ErrorException;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;

Expand Down Expand Up @@ -58,7 +59,18 @@ public function install($source, $destination)
}

if ($item->isDir()) {
if (!file_exists($destinationFile)) {
$fileExists = file_exists($destinationFile);
if (!$fileExists && is_link($destinationFile)) {
throw new \RuntimeException(
sprintf(
'File: "%s" appears to be a broken symlink referencing: "%s"',
$destinationFile,
readlink($destinationFile)
)
);
}

if (!$fileExists) {
mkdir($destinationFile);
}
continue;
Expand Down
31 changes: 31 additions & 0 deletions test/CoreInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ public function testIfFolderExistsInDestinationItemIsSkipped()
$this->assertTrue($this->root->hasChild('destination/folder1/file1.txt'));
}

public function testIfBrokenSymlinkExistsWhereDirShouldBeExceptionIsThrown()
{
$tempSourceDir = sprintf('%s/%s/source', sys_get_temp_dir(), $this->getName());
$tempDestinationDir = sprintf('%s/%s/destination', sys_get_temp_dir(), $this->getName());
mkdir($tempSourceDir, 0777, true);
mkdir($tempDestinationDir, 0777, true);

mkdir(sprintf('%s/directory', $tempSourceDir));

@symlink('nonexistentfolder', sprintf('%s/directory', $tempDestinationDir));

try {
$this->installer->install($tempSourceDir, $tempDestinationDir);
} catch (\RuntimeException $e) {
$this->assertInstanceOf('RuntimeException', $e);
$this->assertEquals(
sprintf(
'File: "%s/directory" appears to be a broken symlink referencing: "nonexistentfolder"',
$tempDestinationDir
),
$e->getMessage()
);
}

rmdir(sprintf('%s/directory', $tempSourceDir));
rmdir($tempSourceDir);

unlink(sprintf('%s/directory', $tempDestinationDir));
rmdir($tempDestinationDir);
}

public function testExcludedFilesAreNotCopied()
{
$exclude = new Exclude(array('file1.txt', 'folder1/file2.txt'));
Expand Down

0 comments on commit 0c75cef

Please sign in to comment.