merged branch SamsonIT/remove_symlink_on_windows (PR #4565)

Commits
-------

fc3ebb8 [FileSystem] added if-windows check
0b58828 [FileSystem] remove symlinks under windows

Discussion
----------

[FileSystem] remove symlinks under windows

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes

When installing assets on Windows with symlink, the following error occurs when symlink-folders already exist. This PR makes sure symlink-folders are removed under Windows.

```
$ app/console assets:install web --symlink
Installing assets using the symlink option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework

  [ErrorException]
  Warning: symlink(): Cannot create symlink, error code(1314) in C:\workspace\erik\roompot\vendor\symfony\symfony\src\Symfony\Component\Filesystem\Filesystem.php line 167

assets:install [--symlink] [--relative] target
```

---------------------------------------------------------------------------

by travisbot at 2012-06-13T09:00:42Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1608541) (merged 0b58828b into 37550d23).

---------------------------------------------------------------------------

by travisbot at 2012-06-13T14:39:32Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1611288) (merged fc3ebb8c into 0f67ca88).
This commit is contained in:
Fabien Potencier 2012-06-13 16:41:41 +02:00
commit c07e9163a6
2 changed files with 20 additions and 1 deletions

View File

@ -97,7 +97,12 @@ class Filesystem
rmdir($file);
} else {
unlink($file);
// https://bugs.php.net/bug.php?id=52176
if (defined('PHP_WINDOWS_VERSION_MAJOR') && is_dir($file)) {
rmdir($file);
} else {
unlink($file);
}
}
}
}

View File

@ -421,6 +421,20 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(is_link($link));
$this->assertEquals($file, readlink($link));
}
/**
* @depends testSymlink
*/
public function testRemoveSymlink()
{
$this->markAsSkippedIfSymlinkIsMissing();
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
$this->filesystem->remove($link);
$this->assertTrue(!is_link($link));
}
public function testSymlinkIsOverwrittenIfPointsToDifferentTarget()
{