[Filesystem] restore ability to create broken symlinks

This commit is contained in:
Nicolas Grekas 2014-12-25 09:15:16 +01:00
parent bad5169f0d
commit 3101202333
3 changed files with 12 additions and 9 deletions

View File

@ -106,6 +106,9 @@ EOT
try {
$filesystem->symlink($relativeOriginDir, $targetDir);
if (!file_exists($targetDir)) {
throw new IOException('Symbolic link is broken');
}
$output->writeln('The assets were installed using symbolic links.');
} catch (IOException $e) {
if (!$input->getOption('relative')) {
@ -116,6 +119,9 @@ EOT
// try again without the relative option
try {
$filesystem->symlink($originDir, $targetDir);
if (!file_exists($targetDir)) {
throw new IOException('Symbolic link is broken');
}
$output->writeln('It looks like your system doesn\'t support relative symbolic links, so the assets were installed by using absolute symbolic links.');
} catch (IOException $e) {
$this->hardCopy($originDir, $targetDir);

View File

@ -286,9 +286,7 @@ class Filesystem
*/
public function symlink($originDir, $targetDir, $copyOnWindows = false)
{
$onWindows = strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN';
if ($onWindows && $copyOnWindows) {
if (defined('PHP_WINDOWS_VERSION_MAJOR') && $copyOnWindows) {
$this->mirror($originDir, $targetDir);
return;
@ -315,10 +313,6 @@ class Filesystem
}
throw new IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir);
}
if (!file_exists($targetDir)) {
throw new IOException(sprintf('Symbolic link "%s" is created but appears to be broken.', $targetDir), 0, null, $targetDir);
}
}
}

View File

@ -686,11 +686,14 @@ class FilesystemTest extends FilesystemTestCase
$file = $this->workspace.DIRECTORY_SEPARATOR.'file';
$link = $this->workspace.DIRECTORY_SEPARATOR.'link';
touch($file);
// $file does not exists right now: creating "broken" links is a wanted feature
$this->filesystem->symlink($file, $link);
$this->assertTrue(is_link($link));
// Create the linked file AFTER creating the link
touch($file);
$this->assertEquals($file, readlink($link));
}