From 31012023338614fe38a4e0b3ae1dcdf613518b88 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 25 Dec 2014 09:15:16 +0100 Subject: [PATCH] [Filesystem] restore ability to create broken symlinks --- .../FrameworkBundle/Command/AssetsInstallCommand.php | 6 ++++++ src/Symfony/Component/Filesystem/Filesystem.php | 8 +------- src/Symfony/Component/Filesystem/Tests/FilesystemTest.php | 7 +++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index d0f60c8426..92a84affd6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -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); diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index d2d2c94d9e..0245b8c265 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -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); - } } } diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 947c636311..4c49f1ee8c 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -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)); }