function Filesystem::junction
Creates an NTFS junction.
Return value
void
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Filesystem.php, line 828
Class
- Filesystem
- @author Jordi Boggiano <j.boggiano@seld.be> @author Johannes M. Schmitt <schmittjoh@gmail.com>
Namespace
Composer\UtilCode
public function junction(string $target, string $junction) {
if (!Platform::isWindows()) {
throw new \LogicException(sprintf('Function %s is not available on non-Windows platform', __CLASS__));
}
if (!is_dir($target)) {
throw new IOException(sprintf('Cannot junction to "%s" as it is not a directory.', $target), 0, null, $target);
}
// Removing any previously junction to ensure clean execution.
if (!is_dir($junction) || $this->isJunction($junction)) {
@rmdir($junction);
}
$cmd = [
'mklink',
'/J',
str_replace('/', DIRECTORY_SEPARATOR, $junction),
Platform::realpath($target),
];
if ($this->getProcess()
->execute($cmd, $output) !== 0) {
throw new IOException(sprintf('Failed to create junction to "%s" at "%s".', $target, $junction), 0, null, $target);
}
clearstatcache(true, $junction);
}