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); $this->io->enableDebugging($startTime);
} }
if ($newWorkDir = $this->getNewWorkingDir($input)) {
$oldWorkingDir = getcwd(); $oldWorkingDir = getcwd();
$this->switchWorkingDir($input); chdir($newWorkDir);
}
$result = parent::doRun($input, $output); $result = parent::doRun($input, $output);
if (isset($oldWorkingDir)) {
chdir($oldWorkingDir); chdir($oldWorkingDir);
}
if (isset($startTime)) { 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'); $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 * @param InputInterface $input
* @throws \RuntimeException * @throws \RuntimeException
*/ */
private function switchWorkingDir(InputInterface $input) private function getNewWorkingDir(InputInterface $input)
{ {
$workingDir = $input->getParameterOption(array('--working-dir', '-d'), getcwd()); $workingDir = $input->getParameterOption(array('--working-dir', '-d'));
if (!is_dir($workingDir)) { if (false !== $workingDir && !is_dir($workingDir)) {
throw new \RuntimeException('Invalid working directory specified.'); throw new \RuntimeException('Invalid working directory specified.');
} }
chdir($workingDir);
return $workingDir;
} }
/** /**