1
0
Fork 0

Remove cygwin php handling in UAC elevation

When called from a native shell and using cygwin PHP, cygpath translates
`/tmp` to `User\AppData\Local\Temp`, rather than `/cygdrive/.../tmp`.
This change does not affect using windows PHP from a Cygwin shell.
pull/9059/head
johnstevenson 2020-07-16 17:14:10 +01:00
parent 11892070d1
commit 8ddbae358d
1 changed files with 10 additions and 30 deletions

View File

@ -380,8 +380,8 @@ TAGSPUBKEY
// see if we can run this operation as an Admin on Windows // see if we can run this operation as an Admin on Windows
if (!is_writable(dirname($localFilename)) if (!is_writable(dirname($localFilename))
&& $io->isInteractive() && $io->isInteractive()
&& $this->isWindowsNonAdminUser($isCygwin)) { && $this->isWindowsNonAdminUser()) {
return $this->tryAsWindowsAdmin($localFilename, $newFilename, $isCygwin); return $this->tryAsWindowsAdmin($localFilename, $newFilename);
} }
$action = 'Composer '.($backupTarget ? 'update' : 'rollback'); $action = 'Composer '.($backupTarget ? 'update' : 'rollback');
@ -467,20 +467,16 @@ TAGSPUBKEY
/** /**
* Returns true if this is a non-admin Windows user account * Returns true if this is a non-admin Windows user account
* *
* @param null|bool $isCygwin Set by method
* @return bool * @return bool
*/ */
protected function isWindowsNonAdminUser(&$isCygwin) protected function isWindowsNonAdminUser()
{ {
$isCygwin = preg_match('/cygwin/i', php_uname()); if (!Platform::isWindows()) {
if (!$isCygwin && !Platform::isWindows()) {
return false; return false;
} }
// fltmc.exe manages filter drivers and errors without admin privileges // fltmc.exe manages filter drivers and errors without admin privileges
$command = sprintf('%sfltmc.exe filters', $isCygwin ? 'cmd.exe /c ' : ''); exec('fltmc.exe filters', $output, $exitCode);
exec($command, $output, $exitCode);
return $exitCode !== 0; return $exitCode !== 0;
} }
@ -492,10 +488,9 @@ TAGSPUBKEY
* *
* @param string $localFilename The composer.phar location * @param string $localFilename The composer.phar location
* @param string $newFilename The downloaded or backup phar * @param string $newFilename The downloaded or backup phar
* @param bool $isCygwin Whether we are running on Cygwin
* @return bool Whether composer.phar has been updated * @return bool Whether composer.phar has been updated
*/ */
protected function tryAsWindowsAdmin($localFilename, $newFilename, $isCygwin) protected function tryAsWindowsAdmin($localFilename, $newFilename)
{ {
$io = $this->getIO(); $io = $this->getIO();
@ -515,15 +510,9 @@ TAGSPUBKEY
$checksum = hash_file('sha256', $newFilename); $checksum = hash_file('sha256', $newFilename);
// format the file names for cmd.exe
if ($isCygwin) {
$source = exec(sprintf("cygpath -w '%s'", $newFilename));
$destination = exec(sprintf("cygpath -w '%s'", $localFilename));
} else {
// cmd's internal move is fussy about backslashes // cmd's internal move is fussy about backslashes
$source = str_replace('/', '\\', $newFilename); $source = str_replace('/', '\\', $newFilename);
$destination = str_replace('/', '\\', $localFilename); $destination = str_replace('/', '\\', $localFilename);
}
$vbs = <<<EOT $vbs = <<<EOT
Set UAC = CreateObject("Shell.Application") Set UAC = CreateObject("Shell.Application")
@ -532,16 +521,7 @@ Wscript.Sleep(300)
EOT; EOT;
file_put_contents($script, $vbs); file_put_contents($script, $vbs);
exec('"'.$script.'"');
if ($isCygwin) {
chmod($script, 0755);
$cygscript = sprintf('"%s"', exec(sprintf("cygpath -w '%s'", $script)));
$command = sprintf("cmd.exe /c '%s'", $cygscript);
} else {
$command = sprintf('"%s"', $script);
}
exec($command);
@unlink($script); @unlink($script);
// see if the file was moved // see if the file was moved