From 615638c7c3a8338d795edb8c6c666136a62c9649 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 27 Oct 2015 15:36:12 +0000 Subject: [PATCH] Simplify bin-compat by removing the nosymlink option, refs #3704 --- doc/06-config.md | 12 ++--- res/composer-schema.json | 4 +- src/Composer/Command/ConfigCommand.php | 2 +- src/Composer/Config.php | 4 +- src/Composer/Installer/LibraryInstaller.php | 7 +-- src/Composer/Util/Filesystem.php | 20 ++++++++ src/Composer/Util/Symlink.php | 54 --------------------- 7 files changed, 32 insertions(+), 71 deletions(-) delete mode 100644 src/Composer/Util/Symlink.php diff --git a/doc/06-config.md b/doc/06-config.md index 05c0c3592..b671095a7 100644 --- a/doc/06-config.md +++ b/doc/06-config.md @@ -1,6 +1,6 @@ # Config -This chapter will describe the `config` section of the `composer.json` +This chapter will describe the `config` section of the `composer.json` [schema](04-schema.md). ## process-timeout @@ -105,11 +105,11 @@ first until the cache fits. ## bin-compat Defaults to `auto`. Determines the compatibility of the binaries to be installed. -If it is `auto` then Composer tries to automatically guess which compatibility mode -to use. If it is `nosymlink` then the binaries will be compatible with Unix-based -operating systems (useful for cases when symlinks are not available). -If its value is `full` then both .bat files for Windows and scripts for Unix-based -operating systems will be installed for each binary. +If it is `auto` then Composer only installs .bat proxy files when on Windows. If +set to `full` then both .bat files for Windows and scripts for Unix-based +operating systems will be installed for each binary. This is mainly useful if you +run Composer inside a linux VM but still want the .bat proxies available for use +in the Windows host OS. ## prepend-autoloader diff --git a/res/composer-schema.json b/res/composer-schema.json index ec7d5869e..f74a9c9b8 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -187,8 +187,8 @@ "description": "The cache max size for the files cache, defaults to \"300MiB\"." }, "bin-compat": { - "enum": ["auto", "nosymlink", "full"], - "description": "The compatibility of the binaries, defaults to \"auto\" (automatically guessed) and can be \"nosymlink\" (compatible with Unix-based systems) or \"full\" (compatible with both Windows and Unix-based systems)." + "enum": ["auto", "full"], + "description": "The compatibility of the binaries, defaults to \"auto\" (automatically guessed) and can be \"full\" (compatible with both Windows and Unix-based systems)." }, "discard-changes": { "type": ["string", "boolean"], diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index f65191f2b..4f06241fc 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -308,7 +308,7 @@ EOT function ($val) { return $val; }, ), 'bin-compat' => array( - function ($val) { return in_array($val, array('auto', 'nosymlink', 'full')); }, + function ($val) { return in_array($val, array('auto', 'full')); }, function ($val) { return $val; } ), 'discard-changes' => array( diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 91f31b084..834598d9e 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -222,9 +222,9 @@ class Config case 'bin-compat': $value = $this->getComposerEnv('COMPOSER_BIN_COMPAT') ?: $this->config[$key]; - if (!in_array($value, array('auto', 'nosymlink', 'full'))) { + if (!in_array($value, array('auto', 'full'))) { throw new \RuntimeException( - "Invalid value for 'bin-compat': {$value}. Expected auto, nosymlink, full" + "Invalid value for 'bin-compat': {$value}. Expected auto, full" ); } diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 769769c90..9c272c9dc 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -229,8 +229,6 @@ class LibraryInstaller implements InstallerInterface } else { $this->installSymlinkBinaries($binPath, $link); } - } elseif ($this->binCompat === "nosymlink") { - $this->installUnixyProxyBinaries($binPath, $link); } elseif ($this->binCompat === "full") { $this->installFullBinaries($binPath, $link, $bin, $package); } @@ -256,10 +254,7 @@ class LibraryInstaller implements InstallerInterface protected function installSymlinkBinaries($binPath, $link) { - try { - $symlink = new Symlink($this->filesystem); - $symlink->symlinkBin($binPath, $link); - } catch (\ErrorException $e) { + if (!$this->filesystem->relativeSymlink($binPath, $link)) { $this->installUnixyProxyBinaries($binPath, $link); } } diff --git a/src/Composer/Util/Filesystem.php b/src/Composer/Util/Filesystem.php index 93b1a4010..88a6123a1 100644 --- a/src/Composer/Util/Filesystem.php +++ b/src/Composer/Util/Filesystem.php @@ -505,6 +505,26 @@ class Filesystem return unlink($path); } + /** + * Creates a relative symlink from $link to $target + * + * @param string $target The path of the binary file to be symlinked + * @param string $link The path where the symlink should be created + * @return bool + */ + public function relativeSymlink($target, $link) + { + $cwd = getcwd(); + + $relativePath = $this->filesystem->findShortestPath($link, $target); + chdir(dirname($link)); + $result = @symlink($relativePath, $link); + + chdir($cwd); + + return (bool) $result; + } + /** * return true if that directory is a symlink. * diff --git a/src/Composer/Util/Symlink.php b/src/Composer/Util/Symlink.php deleted file mode 100644 index 9735e0223..000000000 --- a/src/Composer/Util/Symlink.php +++ /dev/null @@ -1,54 +0,0 @@ - - * 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(); - } - } -}