Tweak and add comments to the working dir fix with global exec, refs #8515
parent
6b8f1c71b6
commit
8d24b61bef
|
@ -92,9 +92,12 @@ EOT
|
||||||
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
|
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getcwd() !== $this->getApplication()->getWorkingDirectory()) {
|
// If the CWD was modified, we restore it to what it was initially, as it was
|
||||||
|
// most likely modified by the global command, and we want exec to run in the local working directory
|
||||||
|
// not the global one
|
||||||
|
if (getcwd() !== $this->getApplication()->getInitialWorkingDirectory()) {
|
||||||
try {
|
try {
|
||||||
chdir($this->getApplication()->getWorkingDirectory());
|
chdir($this->getApplication()->getInitialWorkingDirectory());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new \RuntimeException('Could not switch back to working directory "'.$this->getApplication()->getWorkingDirectory().'"', 0, $e);
|
throw new \RuntimeException('Could not switch back to working directory "'.$this->getApplication()->getWorkingDirectory().'"', 0, $e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,10 +63,9 @@ class Application extends BaseApplication
|
||||||
private $disablePluginsByDefault = false;
|
private $disablePluginsByDefault = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Store the working directory so Composer
|
* @var string Store the initial working directory at startup time
|
||||||
* can switch back to it if there are issues
|
|
||||||
*/
|
*/
|
||||||
private $workingDirectory = '';
|
private $initialWorkingDirectory = '';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -97,7 +96,7 @@ class Application extends BaseApplication
|
||||||
|
|
||||||
$this->io = new NullIO();
|
$this->io = new NullIO();
|
||||||
|
|
||||||
$this->workingDirectory = getcwd();
|
$this->initialWorkingDirectory = getcwd();
|
||||||
|
|
||||||
parent::__construct('Composer', Composer::getVersion());
|
parent::__construct('Composer', Composer::getVersion());
|
||||||
}
|
}
|
||||||
|
@ -139,6 +138,7 @@ class Application extends BaseApplication
|
||||||
if ($newWorkDir = $this->getNewWorkingDir($input)) {
|
if ($newWorkDir = $this->getNewWorkingDir($input)) {
|
||||||
$oldWorkingDir = getcwd();
|
$oldWorkingDir = getcwd();
|
||||||
chdir($newWorkDir);
|
chdir($newWorkDir);
|
||||||
|
$this->initialWorkingDirectory = $newWorkDir;
|
||||||
$io->writeError('Changed CWD to ' . getcwd(), true, IOInterface::DEBUG);
|
$io->writeError('Changed CWD to ' . getcwd(), true, IOInterface::DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,12 +501,12 @@ class Application extends BaseApplication
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the working directoy
|
* Get the working directoy at startup time
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getWorkingDirectory()
|
public function getInitialWorkingDirectory()
|
||||||
{
|
{
|
||||||
return $this->workingDirectory;
|
return $this->initialWorkingDirectory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue