1
0
Fork 0

Add NTFS junction support to Util\Filesystem.

pull/4845/head
Niels Keurentjes 2016-01-28 00:33:11 +01:00
parent cd21505c8d
commit e515eb84e9
1 changed files with 36 additions and 0 deletions

View File

@ -98,6 +98,10 @@ class Filesystem
return $this->unlinkSymlinkedDirectory($directory);
}
if ($this->isJunction($directory)) {
return $this->removeJunction($directory);
}
if (!file_exists($directory) || !is_dir($directory)) {
return true;
}
@ -576,4 +580,36 @@ class Filesystem
return $resolved;
}
/**
* Returns whether the target directory is a Windows NTFS Junction.
*
* @param string $junction Path to check.
* @return bool
*/
public function isJunction($junction)
{
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
return false;
}
$normalized = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $junction), DIRECTORY_SEPARATOR);
$real = rtrim(realpath($normalized), DIRECTORY_SEPARATOR);
return is_dir($normalized) && ($normalized !== $real);
}
/**
* Removes a Windows NTFS junction.
*
* @param string $junction
* @return bool
*/
public function removeJunction($junction)
{
if (!defined('PHP_WINDOWS_VERSION_BUILD')) {
return false;
}
$junction = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $junction), DIRECTORY_SEPARATOR);
$cmd = sprintf('rmdir /S /Q %s', ProcessExecutor::escape($junction));
return $this->getProcess()->execute($cmd, $output) === 0;
}
}