From 863419980dc3c391250db67984cc1dfaf1692334 Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Sat, 5 Jul 2014 13:15:16 +0200 Subject: [PATCH 1/8] Make assets:install auto --- .../Command/AssetsInstallCommand.php | 36 +++++++++++++++++-- .../Component/Filesystem/Filesystem.php | 5 ++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 9aa5453053f0..20549066f436 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; /** @@ -35,6 +36,7 @@ protected function configure() new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'web'), )) ->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it') + ->addOption('auto', null, InputOption::VALUE_NONE, 'Use symlinks if possible, hard copies if not') ->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks') ->setDescription('Installs bundles web assets under a public web directory') ->setHelp(<<php %command.full_name% web --symlink +If you prefer symbolic links but are not sure whether your system supports it, use the +--auto option: + +php %command.full_name% web --auto + To make symlink relative, add the --relative option: php %command.full_name% web --symlink --relative @@ -83,29 +90,52 @@ protected function execute(InputInterface $input, OutputInterface $output) $bundlesDir = $targetArg.'/bundles/'; $filesystem->mkdir($bundlesDir, 0777); - $output->writeln(sprintf('Installing assets as %s', $input->getOption('symlink') ? 'symlinks' : 'hard copies')); + if ($input->getOption('auto')) { + $output->writeln('Trying to install assets as symbolic links.'); + } else { + $output->writeln(sprintf('Installing assets as %s', $input->getOption('symlink') ? 'symlinks' : 'hard copies')); + } + $autoSymlinkFailed = false; foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { + $hardCopy = false; $targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName())); $output->writeln(sprintf('Installing assets for %s into %s', $bundle->getNamespace(), $targetDir)); $filesystem->remove($targetDir); - if ($input->getOption('symlink')) { + if ($input->getOption('symlink') || $input->getOption('auto')) { if ($input->getOption('relative')) { $relativeOriginDir = $filesystem->makePathRelative($originDir, realpath($bundlesDir)); } else { $relativeOriginDir = $originDir; } - $filesystem->symlink($relativeOriginDir, $targetDir); + + try { + $filesystem->symlink($relativeOriginDir, $targetDir); + } catch (IOException $e) { + if ($input->getOption('auto')) { + $hardCopy = true; + $autoSymlinkFailed = true; + } else { + throw $e; + } + } } else { + $hardCopy = true; + } + + if ($hardCopy) { $filesystem->mkdir($targetDir, 0777); // We use a custom iterator to ignore VCS files $filesystem->mirror($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); } } } + if ($input->getOption('auto')) { + $output->writeln(sprintf('Assets were installed as %s.', $autoSymlinkFailed?'hard copies':'symbolic links')); + } } } diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index ca146aa816c9..7882da514cc6 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -293,9 +293,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); + } } } From f03073ec12bd7481483d2e74e29c3aa816b26e14 Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Sat, 5 Jul 2014 16:10:54 +0200 Subject: [PATCH 2/8] assets:install:auto removed unnecessary function_exists calls: as of PHP 5.3 symlink function always exists. --- .../Bundle/FrameworkBundle/Command/AssetsInstallCommand.php | 4 ---- src/Symfony/Component/Filesystem/Filesystem.php | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 20549066f436..72d6b6cc388d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -80,10 +80,6 @@ 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. diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 7882da514cc6..793690edd9c0 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -268,7 +268,7 @@ public function rename($origin, $target, $overwrite = false) */ public function symlink($originDir, $targetDir, $copyOnWindows = false) { - if (!function_exists('symlink') && $copyOnWindows) { + if ($copyOnWindows) { $this->mirror($originDir, $targetDir); return; @@ -377,7 +377,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']; } From a7330c323a8386206a9b042b8fc8b21490e1f868 Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Sat, 5 Jul 2014 18:53:41 +0200 Subject: [PATCH 3/8] assets:install cleaned up code --- .../Command/AssetsInstallCommand.php | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 72d6b6cc388d..5879da76570c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -95,7 +95,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $autoSymlinkFailed = false; foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { - $hardCopy = false; $targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName())); $output->writeln(sprintf('Installing assets for %s into %s', $bundle->getNamespace(), $targetDir)); @@ -112,26 +111,39 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $filesystem->symlink($relativeOriginDir, $targetDir); } catch (IOException $e) { - if ($input->getOption('auto')) { - $hardCopy = true; + if (!$input->getOption('auto')) { + $this->hardCopy($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); $autoSymlinkFailed = true; } else { throw $e; } } } else { - $hardCopy = true; + $this->hardCopy($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); } - if ($hardCopy) { - $filesystem->mkdir($targetDir, 0777); - // We use a custom iterator to ignore VCS files - $filesystem->mirror($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); - } } } + if ($input->getOption('auto')) { - $output->writeln(sprintf('Assets were installed as %s.', $autoSymlinkFailed?'hard copies':'symbolic links')); + if ($autoSymlinkFailed) { + $output->writeln('It looks like your system doesn\'t support symbolic links, so the assets were installed by copying them.'); + } else { + $output->writeln('The assets were installed using symbolic links.'); + } } } + + /** + * Create hardcopy for targetDir + */ + private function hardCopy($originDir, $targetDir, \Traversable $iterator = null) + { + $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)); + } + } From 2ea12dea51f2145ca0707e2cc46d0efe1202f817 Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Mon, 7 Jul 2014 12:45:49 +0200 Subject: [PATCH 4/8] assets:install as mentioned; removed unused itterator from function --- .../FrameworkBundle/Command/AssetsInstallCommand.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 5879da76570c..59df7f7f5dc5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -112,14 +112,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $filesystem->symlink($relativeOriginDir, $targetDir); } catch (IOException $e) { if (!$input->getOption('auto')) { - $this->hardCopy($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); + $this->hardCopy($originDir, $targetDir); $autoSymlinkFailed = true; } else { throw $e; } } } else { - $this->hardCopy($originDir, $targetDir, Finder::create()->ignoreDotFiles(false)->in($originDir)); + $this->hardCopy($originDir, $targetDir); } } @@ -135,9 +135,10 @@ protected function execute(InputInterface $input, OutputInterface $output) } /** - * Create hardcopy for targetDir + * @param string $originDir + * @param string $targetDir */ - private function hardCopy($originDir, $targetDir, \Traversable $iterator = null) + private function hardCopy($originDir, $targetDir) { $filesystem = $this->getContainer()->get('filesystem'); From 25b456b68ce7811f8fa581e0ca0ea935f1cbdb91 Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Mon, 7 Jul 2014 14:57:36 +0200 Subject: [PATCH 5/8] assets:install removed faulty false check --- .../Bundle/FrameworkBundle/Command/AssetsInstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 59df7f7f5dc5..e256f232ba60 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -111,7 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $filesystem->symlink($relativeOriginDir, $targetDir); } catch (IOException $e) { - if (!$input->getOption('auto')) { + if ($input->getOption('auto')) { $this->hardCopy($originDir, $targetDir); $autoSymlinkFailed = true; } else { From 421de0585bad0aa3c96136fe49cb86cd6c0d020d Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Tue, 8 Jul 2014 20:09:16 +0200 Subject: [PATCH 6/8] assets:install --auto -> check if running on windows, if so, use native function mklink instead of symlink --- .../Component/Filesystem/Filesystem.php | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 793690edd9c0..003b89f15a18 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 ($copyOnWindows) { - $this->mirror($originDir, $targetDir); + $onWindows = strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN'; + if ($onWindows && $copyOnWindows) { + $this->mirror($originDir, $targetDir); return; } @@ -286,14 +287,21 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false) } if (!$ok) { - if (true !== @symlink($originDir, $targetDir)) { - $report = error_get_last(); - if (is_array($report)) { - if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) { - 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?'); + if ($onWindows) { + exec("mklink /d {$targetDir} {$originDir}", $output, $return_var); + if ($return_var != 0) { + throw new IOException(sprintf('Failed to create symbolic link on Windows from "%s" to "%s" with error(s): "%s".', $originDir, $targetDir, implode('; ', $output)), 0, null, $targetDir); + } + } else { + if (true !== @symlink($originDir, $targetDir)) { + $report = error_get_last(); + if (is_array($report)) { + if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) { + 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); } - throw new IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir); } if (!file_exists($targetDir)) { From ba950dc731260f4a27fed3018d7a569b6cef7680 Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Thu, 10 Jul 2014 09:12:53 +0200 Subject: [PATCH 7/8] assets:install --auto -> removed mklink functionality, kept onWindows check --- .../Component/Filesystem/Filesystem.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 003b89f15a18..dc349c181420 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -287,21 +287,14 @@ public function symlink($originDir, $targetDir, $copyOnWindows = false) } if (!$ok) { - if ($onWindows) { - exec("mklink /d {$targetDir} {$originDir}", $output, $return_var); - if ($return_var != 0) { - throw new IOException(sprintf('Failed to create symbolic link on Windows from "%s" to "%s" with error(s): "%s".', $originDir, $targetDir, implode('; ', $output)), 0, null, $targetDir); - } - } else { - if (true !== @symlink($originDir, $targetDir)) { - $report = error_get_last(); - if (is_array($report)) { - if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) { - 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?'); - } + if (true !== @symlink($originDir, $targetDir)) { + $report = error_get_last(); + if (is_array($report)) { + if (defined('PHP_WINDOWS_VERSION_MAJOR') && false !== strpos($report['message'], 'error code(1314)')) { + 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); } + throw new IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir); } if (!file_exists($targetDir)) { From 21c85f98c31f9ded5a415dc7516f29fe532711e6 Mon Sep 17 00:00:00 2001 From: Roy Van Ginneken Date: Thu, 18 Sep 2014 08:28:10 +0200 Subject: [PATCH 8/8] assets:install --auto -> removed --auto param and integrated functionality into --symlink --- .../Command/AssetsInstallCommand.php | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index e256f232ba60..b728160f9fab 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -36,7 +36,6 @@ protected function configure() new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'web'), )) ->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it') - ->addOption('auto', null, InputOption::VALUE_NONE, 'Use symlinks if possible, hard copies if not') ->addOption('relative', null, InputOption::VALUE_NONE, 'Make relative symlinks') ->setDescription('Installs bundles web assets under a public web directory') ->setHelp(<<--symlink option: +--symlink option (will fall back to hard copies when symbolic links aren't possible: php %command.full_name% web --symlink -If you prefer symbolic links but are not sure whether your system supports it, use the ---auto option: - -php %command.full_name% web --auto - To make symlink relative, add the --relative option: php %command.full_name% web --symlink --relative @@ -86,13 +80,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $bundlesDir = $targetArg.'/bundles/'; $filesystem->mkdir($bundlesDir, 0777); - if ($input->getOption('auto')) { + if ($input->getOption('symlink')) { $output->writeln('Trying to install assets as symbolic links.'); } else { - $output->writeln(sprintf('Installing assets as %s', $input->getOption('symlink') ? 'symlinks' : 'hard copies')); + $output->writeln('Installing assets as hard copies'); } - $autoSymlinkFailed = false; foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { $targetDir = $bundlesDir.preg_replace('/bundle$/', '', strtolower($bundle->getName())); @@ -101,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $filesystem->remove($targetDir); - if ($input->getOption('symlink') || $input->getOption('auto')) { + if ($input->getOption('symlink')) { if ($input->getOption('relative')) { $relativeOriginDir = $filesystem->makePathRelative($originDir, realpath($bundlesDir)); } else { @@ -110,26 +103,14 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $filesystem->symlink($relativeOriginDir, $targetDir); + $output->writeln('The assets were installed using symbolic links.'); } catch (IOException $e) { - if ($input->getOption('auto')) { - $this->hardCopy($originDir, $targetDir); - $autoSymlinkFailed = true; - } else { - throw $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 { $this->hardCopy($originDir, $targetDir); } - - } - } - - if ($input->getOption('auto')) { - if ($autoSymlinkFailed) { - $output->writeln('It looks like your system doesn\'t support symbolic links, so the assets were installed by copying them.'); - } else { - $output->writeln('The assets were installed using symbolic links.'); } } } 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