From 38c26ae26bf7b56da4c02aca82bada95a438fe10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kocsis=20M=C3=A1t=C3=A9?= Date: Mon, 30 Mar 2015 20:00:12 +0200 Subject: [PATCH] Added Symlink utility class --- src/Composer/Installer/LibraryInstaller.php | 12 ++--- src/Composer/Util/Symlink.php | 54 +++++++++++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/Composer/Util/Symlink.php diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 4f0900a01..20ec97951 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -18,6 +18,7 @@ use Composer\Repository\InstalledRepositoryInterface; use Composer\Package\PackageInterface; use Composer\Util\Filesystem; use Composer\Util\ProcessExecutor; +use Composer\Util\Symlink; /** * Package installation manager. @@ -256,15 +257,10 @@ class LibraryInstaller implements InstallerInterface { $cwd = getcwd(); try { - // under linux symlinks are not always supported for example - // when using it in smbfs mounted folder - $relativeBin = $this->filesystem->findShortestPath($link, $binPath); - chdir(dirname($link)); - if (false === symlink($relativeBin, $link)) { - throw new \ErrorException(); - } + $symlink = new Symlink($this->filesystem); + $symlink->symlinkBin($binPath, $link); } catch (\ErrorException $e) { - $this->installUnixyProxyBinaries($binPath, $link); + $this->installUnixyProxyBinaries($binPath, $link); } chdir($cwd); } diff --git a/src/Composer/Util/Symlink.php b/src/Composer/Util/Symlink.php new file mode 100644 index 000000000..146c57f55 --- /dev/null +++ b/src/Composer/Util/Symlink.php @@ -0,0 +1,54 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Util; + +use Composer\Config; + +/** + * @author Kocsis Máté + */ +class Symlink +{ + protected $filesystem; + + /** + * Initializes the symlinking utility. + * + * @param Filesystem $filesystem + */ + public function __construct(Filesystem $filesystem = null) + { + $this->filesystem = $filesystem ?: new Filesystem(); + } + + /** + * Creates a symlink for a binary file at a given path. + * + * @param string $binPath The path of the binary file to be symlinked + * @param string $link The path where the symlink should be created + * @throws \ErrorException + */ + public function symlinkBin($binPath, $link) + { + $cwd = getcwd(); + + $relativeBin = $this->filesystem->findShortestPath($link, $binPath); + chdir(dirname($link)); + $result = symlink($relativeBin, $link); + + chdir($cwd); + if ($result === false) { + throw new \ErrorException(); + } + } +}