1
0
Fork 0

Fully implemented junctioning on Windows for path repositories.

pull/4845/head
Niels Keurentjes 2016-01-28 00:56:02 +01:00
parent e515eb84e9
commit 5489586436
2 changed files with 29 additions and 3 deletions

View File

@ -48,9 +48,16 @@ class PathDownloader extends FileDownloader
} }
try { try {
$shortestPath = $this->filesystem->findShortestPath($path, $realUrl); if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$fileSystem->symlink($shortestPath, $path); // Implement symlinks as junctions on Windows, with magic shell hackery
$this->io->writeError(sprintf(' Symlinked from %s', $url)); $this->filesystem->junction($realUrl, $path);
$this->io->writeError(sprintf(' Junctioned from %s', $url));
} else {
$shortestPath = $this->filesystem->findShortestPath($path, $realUrl);
$fileSystem->symlink($shortestPath, $path);
$this->io->writeError(sprintf(' Symlinked from %s', $url));
}
} catch (IOException $e) { } catch (IOException $e) {
$fileSystem->mirror($realUrl, $path); $fileSystem->mirror($realUrl, $path);
$this->io->writeError(sprintf(' Mirrored from %s', $url)); $this->io->writeError(sprintf(' Mirrored from %s', $url));

View File

@ -14,6 +14,7 @@ namespace Composer\Util;
use RecursiveDirectoryIterator; use RecursiveDirectoryIterator;
use RecursiveIteratorIterator; use RecursiveIteratorIterator;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
/** /**
@ -581,6 +582,24 @@ class Filesystem
return $resolved; return $resolved;
} }
/**
* Creates an NTFS junction.
*
* @param string $originDir
* @param string $targetDir
*/
public function junction($originDir, $targetDir)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$cmd = sprintf('mklink /J %s %s',
ProcessExecutor::escape(str_replace('/', DIRECTORY_SEPARATOR, $targetDir)),
ProcessExecutor::escape(realpath($originDir)));
if ($this->getProcess()->execute($cmd, $output) === 0)
return;
}
throw new IOException(sprintf('Failed to create symbolic link from "%s" to "%s".', $originDir, $targetDir), 0, null, $targetDir);
}
/** /**
* Returns whether the target directory is a Windows NTFS Junction. * Returns whether the target directory is a Windows NTFS Junction.
* *