From 1522b6d26b12bd1a514569b6e20790cd98b40e2a Mon Sep 17 00:00:00 2001 From: Stefan Rausch Date: Thu, 7 May 2015 13:24:28 +0200 Subject: [PATCH 1/3] fixed wipe feature by removing the double quotes in the shell command, added 'symlink to current build copy' feature --- .gitignore | 1 + PHPCI/Plugin/CopyBuild.php | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 63e81c5b..9e56f272 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ PHPCI/Store/MigrationStore.php PHPCI/Store/Base/MigrationStoreBase.php local_vars.php Tests/PHPCI/config.yml +/nbproject/ \ No newline at end of file diff --git a/PHPCI/Plugin/CopyBuild.php b/PHPCI/Plugin/CopyBuild.php index 7f447291..d5aa5e3f 100644 --- a/PHPCI/Plugin/CopyBuild.php +++ b/PHPCI/Plugin/CopyBuild.php @@ -26,6 +26,7 @@ class CopyBuild implements \PHPCI\Plugin protected $wipe; protected $phpci; protected $build; + protected $symlink; /** * Set up the plugin, configure options, etc. @@ -41,6 +42,7 @@ class CopyBuild implements \PHPCI\Plugin $this->directory = isset($options['directory']) ? $options['directory'] : $path; $this->wipe = isset($options['wipe']) ? (bool)$options['wipe'] : false; $this->ignore = isset($options['respect_ignore']) ? (bool)$options['respect_ignore'] : false; + $this->symlink = isset($options['symlink_to_current']) ? $options['symlink_to_current'] : false; } /** @@ -65,6 +67,10 @@ class CopyBuild implements \PHPCI\Plugin $this->deleteIgnoredFiles(); + if ($success && $this->symlink) { + $success = $this->createSymlinkToCurrentBuild(); + } + return $success; } @@ -75,7 +81,7 @@ class CopyBuild implements \PHPCI\Plugin protected function wipeExistingDirectory() { if ($this->wipe === true && $this->directory != '/' && is_dir($this->directory)) { - $cmd = 'rm -Rf "%s*"'; + $cmd = 'rm -Rf %s*'; $success = $this->phpci->executeCommand($cmd, $this->directory); if (!$success) { @@ -99,4 +105,30 @@ class CopyBuild implements \PHPCI\Plugin } } } + + /** + * Create symlink to current copy of build directory. + * Info: Does not work on windows systems. + * @return boolean + */ + protected function createSymlinkToCurrentBuild() + { + $success = true; + + if (!IS_WIN) { + $cmd = 'rm "%s" && ln -s "%s" "%s"'; + + $dir = rtrim($this->directory, '/') . '/'; + $this->phpci->log('Try to create symlink: '.$this->symlink.' --> '.$dir.$this->build->getId()); + $success = $this->phpci->executeCommand($cmd, $this->symlink, $dir.$this->build->getId(), $this->symlink); + + if (!$success) { + $this->phpci->logFailure('Unable to create symlink: '.$this->symlink.' --> '.$dir.$this->build->getId()); + } else { + $this->phpci->log('Symlink successfully created.'); + } + } + + return $success; + } } From dcc7799e79499b41ce5cd86594deaa6aab18fae4 Mon Sep 17 00:00:00 2001 From: Stefan Rausch Date: Fri, 8 May 2015 08:43:03 +0200 Subject: [PATCH 2/3] fixed wipe feature by moving the wildcard '*' out of the quotes to prevent escaping of the wildcard character --- PHPCI/Plugin/CopyBuild.php | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/PHPCI/Plugin/CopyBuild.php b/PHPCI/Plugin/CopyBuild.php index d5aa5e3f..3217237a 100644 --- a/PHPCI/Plugin/CopyBuild.php +++ b/PHPCI/Plugin/CopyBuild.php @@ -26,7 +26,6 @@ class CopyBuild implements \PHPCI\Plugin protected $wipe; protected $phpci; protected $build; - protected $symlink; /** * Set up the plugin, configure options, etc. @@ -42,7 +41,6 @@ class CopyBuild implements \PHPCI\Plugin $this->directory = isset($options['directory']) ? $options['directory'] : $path; $this->wipe = isset($options['wipe']) ? (bool)$options['wipe'] : false; $this->ignore = isset($options['respect_ignore']) ? (bool)$options['respect_ignore'] : false; - $this->symlink = isset($options['symlink_to_current']) ? $options['symlink_to_current'] : false; } /** @@ -67,10 +65,6 @@ class CopyBuild implements \PHPCI\Plugin $this->deleteIgnoredFiles(); - if ($success && $this->symlink) { - $success = $this->createSymlinkToCurrentBuild(); - } - return $success; } @@ -81,7 +75,7 @@ class CopyBuild implements \PHPCI\Plugin protected function wipeExistingDirectory() { if ($this->wipe === true && $this->directory != '/' && is_dir($this->directory)) { - $cmd = 'rm -Rf %s*'; + $cmd = 'rm -Rf "%s"*'; $success = $this->phpci->executeCommand($cmd, $this->directory); if (!$success) { @@ -105,30 +99,4 @@ class CopyBuild implements \PHPCI\Plugin } } } - - /** - * Create symlink to current copy of build directory. - * Info: Does not work on windows systems. - * @return boolean - */ - protected function createSymlinkToCurrentBuild() - { - $success = true; - - if (!IS_WIN) { - $cmd = 'rm "%s" && ln -s "%s" "%s"'; - - $dir = rtrim($this->directory, '/') . '/'; - $this->phpci->log('Try to create symlink: '.$this->symlink.' --> '.$dir.$this->build->getId()); - $success = $this->phpci->executeCommand($cmd, $this->symlink, $dir.$this->build->getId(), $this->symlink); - - if (!$success) { - $this->phpci->logFailure('Unable to create symlink: '.$this->symlink.' --> '.$dir.$this->build->getId()); - } else { - $this->phpci->log('Symlink successfully created.'); - } - } - - return $success; - } } From a26a141046405a483e6dc961e60e4d017a0b819b Mon Sep 17 00:00:00 2001 From: Stefan Rausch Date: Mon, 11 May 2015 10:02:51 +0200 Subject: [PATCH 3/3] cleaned up gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9e56f272..d1f52e6d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,4 @@ PHPCI/Model/Base/MigrationBase.php PHPCI/Store/MigrationStore.php PHPCI/Store/Base/MigrationStoreBase.php local_vars.php -Tests/PHPCI/config.yml -/nbproject/ \ No newline at end of file +Tests/PHPCI/config.yml \ No newline at end of file