diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 9aa5453053f0f..b728160f9fabb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Finder\Finder; /** @@ -47,7 +48,7 @@ protected function configure() "Resources/public" directory of each bundle will be copied into it. To create a symlink to each bundle instead of copying its assets, use the ---symlink option: +--symlink option (will fall back to hard copies when symbolic links aren't possible: php %command.full_name% web --symlink @@ -73,17 +74,17 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target'))); } - if (!function_exists('symlink') && $input->getOption('symlink')) { - throw new \InvalidArgumentException('The symlink() function is not available on your system. You need to install the assets without the --symlink option.'); - } - $filesystem = $this->getContainer()->get('filesystem'); // Create the bundles directory otherwise symlink will fail. $bundlesDir = $targetArg.'/bundles/'; $filesystem->mkdir($bundlesDir, 0777); - $output->writeln(sprintf('Installing assets as %s', $input->getOption('symlink') ? 'symlinks' : 'hard copies')); + if ($input->getOption('symlink')) { + $output->writeln('Trying to install assets as symbolic links.'); + } else { + $output->writeln('Installing assets as hard copies'); + } foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { @@ -99,13 +100,32 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { $relativeOriginDir = $originDir; } - $filesystem->symlink($relativeOriginDir, $targetDir); + + try { + $filesystem->symlink($relativeOriginDir, $targetDir); + $output->writeln('The assets were installed using symbolic links.'); + } catch (IOException $e) { + $this->hardCopy($originDir, $targetDir); + $output->writeln('It looks like your system doesn\'t support symbolic links, so the assets were installed by copying them.'); + } } else { - $filesystem->mkdir($targetDir, 0777); - // We use a custom iterator to ignore VCS files - $filesystem->mirror($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); + $this->hardCopy($originDir, $targetDir); } } } } + + /** + * @param string $originDir + * @param string $targetDir + */ + private function hardCopy($originDir, $targetDir) + { + $filesystem = $this->getContainer()->get('filesystem'); + + $filesystem->mkdir($targetDir, 0777); + // We use a custom iterator to ignore VCS files + $filesystem->mirror($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); + } + } diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index ca146aa816c9e..dc349c181420b 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -268,9 +268,10 @@ public function rename($origin, $target, $overwrite = false) */ public function symlink($originDir, $targetDir, $copyOnWindows = false) { - if (!function_exists('symlink') && $copyOnWindows) { - $this->mirror($originDir, $targetDir); + $onWindows = strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN'; + if ($onWindows && $copyOnWindows) { + $this->mirror($originDir, $targetDir); return; } @@ -293,9 +294,12 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false) throw new IOException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?'); } } - 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); + } } } @@ -374,7 +378,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o } $copyOnWindows = false; - if (isset($options['copy_on_windows']) && !function_exists('symlink')) { + if (isset($options['copy_on_windows'])) { $copyOnWindows = $options['copy_on_windows']; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy