Permalink
Browse files

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
  • Loading branch information...
2 parents e1c8a2f + 94bee7a commit 3e2b39dd21ca481a39e652df364cfbb28987e7e6 @fabpot fabpot committed Apr 20, 2012
@@ -152,6 +152,8 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false)
return;
}
+ $this->mkdir(dirname($targetDir));
+
$ok = false;
if (is_link($targetDir)) {
if (readlink($targetDir) != $originDir) {
@@ -454,6 +454,23 @@ public function testSymlinkIsNotOverwrittenIfAlreadyCreated()
$this->assertEquals($file, readlink($link));
}
+ public function testSymlinkCreatesTargetDirectoryIfItDoesNotExist()
+ {
+ $this->markAsSkippedIfSymlinkIsMissing();
+
+ $file = $this->workspace.DIRECTORY_SEPARATOR.'file';
+ $link1 = $this->workspace.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'link';
+ $link2 = $this->workspace.DIRECTORY_SEPARATOR.'dir'.DIRECTORY_SEPARATOR.'subdir'.DIRECTORY_SEPARATOR.'link';
+
+ $this->filesystem->symlink($file, $link1);
+ $this->filesystem->symlink($file, $link2);
+
+ $this->assertTrue(is_link($link1));
+ $this->assertEquals($file, readlink($link1));
+ $this->assertTrue(is_link($link2));
+ $this->assertEquals($file, readlink($link2));
+ }
+
/**
* @dataProvider providePathsForMakePathRelative
*/

0 comments on commit 3e2b39d

Please sign in to comment.