Skip to content

Commit efad5d5

Browse files
committed
[Filesystem] Prevented infiite loop on windows while calling mirror on symlink. Added test for mirroring symlinks.
1 parent 127cff0 commit efad5d5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
229229
}
230230

231231
foreach ($iterator as $file) {
232-
$target = $targetDir.'/'.str_replace($originDir.DIRECTORY_SEPARATOR, '', $file->getPathname());
232+
$target = str_replace($originDir, $targetDir, $file->getPathname());
233233

234-
if (is_link($file)) {
235-
$this->symlink($file, $target);
236-
} elseif (is_dir($file)) {
234+
if (is_dir($file)) {
237235
$this->mkdir($target);
236+
} elseif (!$copyOnWindows && is_link($file)) {
237+
$this->symlink($file, $target);
238238
} elseif (is_file($file) || ($copyOnWindows && is_link($file))) {
239239
$this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
240240
} else {

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,25 @@ public function testMirrorCopiesFilesAndDirectoriesRecursively()
483483
$this->assertFileEquals($file2, $targetPath.'file2');
484484
}
485485

486+
public function testMirrorCopiesLinks()
487+
{
488+
$this->markAsSkippeIfSymlinkIsMissing();
489+
490+
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
491+
492+
mkdir($sourcePath);
493+
file_put_contents($sourcePath.'file1', 'FILE1');
494+
symlink($sourcePath.'file1', $sourcePath.'link1');
495+
496+
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
497+
498+
$this->filesystem->mirror($sourcePath, $targetPath);
499+
500+
$this->assertTrue(is_dir($targetPath));
501+
$this->assertFileEquals($sourcePath.'file1', $targetPath.DIRECTORY_SEPARATOR.'link1');
502+
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
503+
}
504+
486505
/**
487506
* @dataProvider providePathsForIsAbsolutePath
488507
*/

0 commit comments

Comments
 (0)