Skip to content

Commit f5a2dcc

Browse files
committed
merged branch michal-pipa/symlink-fix (PR #4012)
Commits ------- 94bee7a [Filesystem] symlink() creates target directories Discussion ---------- [Filesystem] symlink() creates target directories Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes [![Build Status](https://secure.travis-ci.org/michal-pipa/symfony.png?branch=symlink-fix)](http://travis-ci.org/michal-pipa/symfony) Fixes the following tickets: #3967 Todo: - Changed symlink() method behavior to recursively create target directory if it does not exist. It makes Filesystem component methods more consistent since copy() does the same. It is also more convenient. Also mirror() fails to create symlink in non-existent directory (if we don't want to change symlink(), than we need to fix mirror()). Fixes: #3967
2 parents 0ca4555 + d732070 commit f5a2dcc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Filesystem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
152152
return;
153153
}
154154

155+
$this->mkdir(dirname($targetDir));
156+
155157
$ok = false;
156158
if (is_link($targetDir)) {
157159
if (readlink($targetDir) != $originDir) {

Tests/FilesystemTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,23 @@ public function testSymlinkIsNotOverwrittenIfAlreadyCreated()
454454
$this->assertEquals($file, readlink($link));
455455
}
456456

457+
public function testSymlinkCreatesTargetDirectoryIfItDoesNotExist()
458+
{
459+
$this->markAsSkippedIfSymlinkIsMissing();
460+
461+
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
462+
$link1 = $this->workspace.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'link';
463+
$link2 = $this->workspace.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'subdir'.DIRECTORY_SEPARATOR.'link';
464+
465+
$this->filesystem->symlink($file, $link1);
466+
$this->filesystem->symlink($file, $link2);
467+
468+
$this->assertTrue(is_link($link1));
469+
$this->assertEquals($file, readlink($link1));
470+
$this->assertTrue(is_link($link2));
471+
$this->assertEquals($file, readlink($link2));
472+
}
473+
457474
/**
458475
* @dataProvider providePathsForMakePathRelative
459476
*/

0 commit comments

Comments
 (0)