1
0
Fork 0

Merge remote-tracking branch 'hakre/patch-1'

pull/3320/head
Jordi Boggiano 2014-10-07 13:45:32 +01:00
commit 923191a489
2 changed files with 47 additions and 2 deletions

View File

@ -181,9 +181,9 @@ class Filesystem
*/ */
public function unlink($path) public function unlink($path)
{ {
if (!@unlink($path)) { if (!@$this->unlinkImplementation($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals // retry after a bit on windows since it tends to be touchy with mass removals
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@unlink($path))) { if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(350000) && !@$this->unlinkImplementation($path))) {
$error = error_get_last(); $error = error_get_last();
$message = 'Could not delete '.$path.': ' . @$error['message']; $message = 'Could not delete '.$path.': ' . @$error['message'];
if (defined('PHP_WINDOWS_VERSION_BUILD')) { if (defined('PHP_WINDOWS_VERSION_BUILD')) {
@ -489,4 +489,22 @@ class Filesystem
{ {
return new ProcessExecutor; return new ProcessExecutor;
} }
/**
* delete symbolic link implementation (commonly known as "unlink()")
*
* symbolic links on windows which link to directories need rmdir instead of unlink
*
* @param string $path
*
* @return bool
*/
private function unlinkImplementation($path)
{
if (defined('PHP_WINDOWS_VERSION_BUILD') && is_dir($path) && is_link($path)) {
return rmdir($path);
}
return unlink($path);
}
} }

View File

@ -176,4 +176,31 @@ class FilesystemTest extends TestCase
array('phar://c:../Foo', 'phar://c:../Foo'), array('phar://c:../Foo', 'phar://c:../Foo'),
); );
} }
/**
* @link https://github.com/composer/composer/issues/3157
*/
public function testUnlinkSymlinkedDirectory()
{
$tmp = sys_get_temp_dir();
$basepath = $tmp . "/composer_testdir";
$symlinked = $basepath . "/linked";
@mkdir($basepath . "/real", 0777, true);
touch($basepath . "/real/FILE");
$result = @symlink($basepath . "/real", $symlinked);
if (!$result) {
$this->markTestSkipped('Symbolic links for directories not supported on this platform');
}
if (!is_dir($symlinked)) {
$this->fail('Precondition assertion failed (is_dir is false on symbolic link to directory).');
}
$fs = new Filesystem();
$result = $fs->unlink($symlinked);
$this->assertTrue($result);
$this->assertFalse(file_exists($symlinked));
}
} }