diff --git a/Filesystem.php b/Filesystem.php index 76dab0354a..a2a36f5386 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -232,12 +232,12 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o } foreach ($iterator as $file) { - $target = $targetDir.'/'.str_replace($originDir.DIRECTORY_SEPARATOR, '', $file->getPathname()); + $target = str_replace($originDir, $targetDir, $file->getPathname()); - if (is_link($file)) { - $this->symlink($file, $target); - } elseif (is_dir($file)) { + if (is_dir($file)) { $this->mkdir($target); + } elseif (!$copyOnWindows && is_link($file)) { + $this->symlink($file, $target); } elseif (is_file($file) || ($copyOnWindows && is_link($file))) { $this->copy($file, $target, isset($options['override']) ? $options['override'] : false); } else { diff --git a/Tests/FilesystemTest.php b/Tests/FilesystemTest.php index f1c8808dbf..6b4e33368d 100644 --- a/Tests/FilesystemTest.php +++ b/Tests/FilesystemTest.php @@ -494,6 +494,25 @@ public function testMirrorCopiesFilesAndDirectoriesRecursively() $this->assertFileEquals($file2, $targetPath.'file2'); } + public function testMirrorCopiesLinks() + { + $this->markAsSkippeIfSymlinkIsMissing(); + + $sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR; + + mkdir($sourcePath); + file_put_contents($sourcePath.'file1', 'FILE1'); + symlink($sourcePath.'file1', $sourcePath.'link1'); + + $targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR; + + $this->filesystem->mirror($sourcePath, $targetPath); + + $this->assertTrue(is_dir($targetPath)); + $this->assertFileEquals($sourcePath.'file1', $targetPath.DIRECTORY_SEPARATOR.'link1'); + $this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1')); + } + /** * @dataProvider providePathsForIsAbsolutePath */