8000 [Filesystem] symlink use RealPath instead LinkTarget · symfony/symfony@a8b8d33 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8b8d33

Browse files
aitboudadfabpot
authored andcommitted
[Filesystem] symlink use RealPath instead LinkTarget
1 parent 6945a2a commit a8b8d33

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
405405
}
406406
} else {
407407
if (is_link($file)) {
408-
$this->symlink($file->getLinkTarget(), $target);
408+
$this->symlink($file->getRealPath(), $target);
409409
} elseif (is_dir($file)) {
410410
$this->mkdir($target);
411411
} elseif (is_file($file)) {

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,31 @@ public function testMirrorCopiesLinkedDirectoryContents()
899899
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
900900
}
901901

902+
public function testMirrorCopiesRelativeLinkedContents()
903+
{
904+
$this->markAsSkippedIfSymlinkIsMissing();
905+
906+
$sourcePath = $this->workspace.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR;
907+
$oldPath = getcwd();
908+
909+
mkdir($sourcePath.'nested/', 0777, true);
910+
file_put_contents($sourcePath.'/nested/file1.txt', 'FILE1');
911+
// Note: Create relative symlink
912+
chdir($sourcePath);
913+
symlink('nested', 'link1');
914+
915+
chdir($oldPath);
916+
917+
$targetPath = $this->workspace.DIRECTORY_SEPARATOR.'target'.DIRECTORY_SEPARATOR;
918+
919+
$this->filesystem->mirror($sourcePath, $targetPath);
920+
921+
$this->assertTrue(is_dir($targetPath));
922+
$this->assertFileEquals($sourcePath.'/nested/file1.txt', $targetPath.DIRECTORY_SEPARATOR.'link1/file1.txt');
923+
$this->assertTrue(is_link($targetPath.DIRECTORY_SEPARATOR.'link1'));
924+
$this->assertEquals($sourcePath.'nested', readlink($targetPath.DIRECTORY_SEPARATOR.'link1'));
925+
}
926+
902927
/**
903928
* @dataProvider providePathsForIsAbsolutePath
904929
*/

0 commit comments

Comments
 (0)
0