diff --git a/PHPCI/Builder.php b/PHPCI/Builder.php index 619c0b38..b2a135f4 100644 --- a/PHPCI/Builder.php +++ b/PHPCI/Builder.php @@ -215,15 +215,6 @@ class Builder implements LoggerAwareInterface $this->pluginExecutor->executePlugins($this->config, 'failure'); $this->buildLogger->logFailure(Lang::get('build_failed')); } - - // Clean up: - $this->buildLogger->log(Lang::get('removing_build')); - - $cmd = 'rm -Rf "%s"'; - if (IS_WIN) { - $cmd = 'rmdir /S /Q "%s"'; - } - $this->executeCommand($cmd, rtrim($this->buildPath, '/')); } catch (\Exception $ex) { $this->build->setStatus(Build::STATUS_FAILED); $this->buildLogger->logFailure(Lang::get('exception') . $ex->getMessage()); @@ -233,6 +224,11 @@ class Builder implements LoggerAwareInterface // Update the build in the database, ping any external services, etc. $this->build->sendStatusPostback(); $this->build->setFinished(new \DateTime()); + + // Clean up: + $this->buildLogger->log(Lang::get('removing_build')); + $this->build->removeBuildDirectory(); + $this->store->save($this->build); } @@ -287,7 +283,7 @@ class Builder implements LoggerAwareInterface */ protected function setupBuild() { - $this->buildPath = PHPCI_DIR . 'PHPCI/build/' . $this->build->getId() . '/'; + $this->buildPath = $this->build->getBuildPath() . '/'; $this->build->currentBuildPath = $this->buildPath; $this->interpolator->setupInterpolationVars( diff --git a/PHPCI/Command/RunCommand.php b/PHPCI/Command/RunCommand.php index 0cbd8e6a..c2c352e6 100644 --- a/PHPCI/Command/RunCommand.php +++ b/PHPCI/Command/RunCommand.php @@ -166,7 +166,7 @@ class RunCommand extends Command $build->setStatus(Build::STATUS_FAILED); $build->setFinished(new \DateTime()); $store->save($build); - $this->removeBuildDirectory($build); + $build->removeBuildDirectory(); continue; } @@ -175,19 +175,4 @@ class RunCommand extends Command return $rtn; } - - protected function removeBuildDirectory($build) - { - $buildPath = PHPCI_DIR . 'PHPCI/build/' . $build->getId() . '/'; - - if (is_dir($buildPath)) { - $cmd = 'rm -Rf "%s"'; - - if (IS_WIN) { - $cmd = 'rmdir /S /Q "%s"'; - } - - shell_exec($cmd); - } - } } diff --git a/PHPCI/Model/Build.php b/PHPCI/Model/Build.php index 3d07778a..2681498f 100644 --- a/PHPCI/Model/Build.php +++ b/PHPCI/Model/Build.php @@ -217,4 +217,28 @@ class Build extends BuildBase { return array($builder, $file, $line, $message); } + + /** + * Return the path to run this build into. + * + * @return string + */ + public function getBuildPath() + { + return PHPCI_BUILD_ROOT_DIR . $this->getId(); + } + + /** + * Removes the build directory. + */ + public function removeBuildDirectory() + { + $buildPath = $this->getBuildPath(); + + if (!is_dir($buildPath)) { + return; + } + + exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm -Rf "%s"', $buildPath)); + } } diff --git a/PHPCI/Service/BuildService.php b/PHPCI/Service/BuildService.php index ca2336c8..a95ac44f 100644 --- a/PHPCI/Service/BuildService.php +++ b/PHPCI/Service/BuildService.php @@ -112,6 +112,7 @@ class BuildService */ public function deleteBuild(Build $build) { + $build->removeBuildDirectory(); return $this->buildStore->delete($build); } } diff --git a/vars.php b/vars.php index b622ab31..98c07377 100644 --- a/vars.php +++ b/vars.php @@ -16,6 +16,11 @@ if (!defined('PHPCI_BIN_DIR')) { define('PHPCI_BIN_DIR', PHPCI_DIR . 'vendor/bin/'); } +// Define PHPCI_BUILD_ROOT_DIR +if (!defined('PHPCI_BUILD_ROOT_DIR')) { + define('PHPCI_BUILD_ROOT_DIR', PHPCI_DIR . 'PHPCI/build/'); +} + // Should PHPCI run the Shell plugin? if (!defined('ENABLE_SHELL_PLUGIN')) { define('ENABLE_SHELL_PLUGIN', false);