From c9ddc25ce655ece54e1840f1b3dec192e5eca870 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Mon, 7 Sep 2015 23:26:11 +0100 Subject: [PATCH 1/2] Throw exception if broken link is present where directory should be --- src/CoreInstaller.php | 14 +++++++++++++- test/CoreInstallerTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/CoreInstaller.php b/src/CoreInstaller.php index e22e8ad..2a6ba89 100644 --- a/src/CoreInstaller.php +++ b/src/CoreInstaller.php @@ -3,6 +3,7 @@ namespace AydinHassan\MagentoCoreComposerInstaller; use Composer\Util\Filesystem; +use ErrorException; use RecursiveIteratorIterator; use RecursiveDirectoryIterator; @@ -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; diff --git a/test/CoreInstallerTest.php b/test/CoreInstallerTest.php index 565d98b..1e954bc 100644 --- a/test/CoreInstallerTest.php +++ b/test/CoreInstallerTest.php @@ -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')); From 738458a47c59179975546151e1ed07eb1ca48c5e Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Mon, 7 Sep 2015 23:34:09 +0100 Subject: [PATCH 2/2] Allow HHVM to fail --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7351a46..2f07140 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,10 @@ php: - 5.6 - hhvm +matrix: + allow_failures: + - php: hhvm + install: - composer self-update - composer install --prefer-source