1
0
Fork 0

Do not chdir unless necessary

pull/1718/head
Jordi Boggiano 2013-03-15 15:21:22 +01:00
parent 7b549010d5
commit 979db8539d
1 changed files with 12 additions and 7 deletions

View File

@ -105,12 +105,16 @@ class Application extends BaseApplication
$this->io->enableDebugging($startTime);
}
$oldWorkingDir = getcwd();
$this->switchWorkingDir($input);
if ($newWorkDir = $this->getNewWorkingDir($input)) {
$oldWorkingDir = getcwd();
chdir($newWorkDir);
}
$result = parent::doRun($input, $output);
chdir($oldWorkingDir);
if (isset($oldWorkingDir)) {
chdir($oldWorkingDir);
}
if (isset($startTime)) {
$output->writeln('<info>Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MB), time: '.round(microtime(true) - $startTime, 2).'s');
@ -123,13 +127,14 @@ class Application extends BaseApplication
* @param InputInterface $input
* @throws \RuntimeException
*/
private function switchWorkingDir(InputInterface $input)
private function getNewWorkingDir(InputInterface $input)
{
$workingDir = $input->getParameterOption(array('--working-dir', '-d'), getcwd());
if (!is_dir($workingDir)) {
$workingDir = $input->getParameterOption(array('--working-dir', '-d'));
if (false !== $workingDir && !is_dir($workingDir)) {
throw new \RuntimeException('Invalid working directory specified.');
}
chdir($workingDir);
return $workingDir;
}
/**