Merge pull request #424 from Block8/NamelessCoder-patch-2
Updated CopyBuild "wipe" option, fixes #346
This commit is contained in:
commit
0bde74b34a
|
@ -22,6 +22,7 @@ class CopyBuild implements \PHPCI\Plugin
|
||||||
{
|
{
|
||||||
protected $directory;
|
protected $directory;
|
||||||
protected $ignore;
|
protected $ignore;
|
||||||
|
protected $wipe;
|
||||||
protected $phpci;
|
protected $phpci;
|
||||||
protected $build;
|
protected $build;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ class CopyBuild implements \PHPCI\Plugin
|
||||||
$this->phpci = $phpci;
|
$this->phpci = $phpci;
|
||||||
$this->build = $build;
|
$this->build = $build;
|
||||||
$this->directory = isset($options['directory']) ? $options['directory'] : $path;
|
$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->ignore = isset($options['respect_ignore']) ? (bool)$options['respect_ignore'] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +47,33 @@ class CopyBuild implements \PHPCI\Plugin
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->wipeExistingDirectory();
|
||||||
|
|
||||||
$cmd = 'mkdir -p "%s" && cp -R "%s" "%s"';
|
$cmd = 'mkdir -p "%s" && cp -R "%s" "%s"';
|
||||||
if (IS_WIN) {
|
if (IS_WIN) {
|
||||||
$cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"';
|
$cmd = 'mkdir -p "%s" && xcopy /E "%s" "%s"';
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->phpci->executeCommand($cmd, $this->directory, $build, $this->directory);
|
$success = $this->phpci->executeCommand($cmd, $this->directory, $build, $this->directory);
|
||||||
|
|
||||||
|
$this->deleteIgnoredFiles();
|
||||||
|
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function wipeExistingDirectory()
|
||||||
|
{
|
||||||
|
if ($this->wipe == true && $this->directory != '/' && is_dir($this->directory)) {
|
||||||
|
$cmd = 'rm -Rf "%s*"';
|
||||||
|
$success = $this->phpci->executeCommand($cmd, $this->directory);
|
||||||
|
if (!$success) {
|
||||||
|
throw new \Exception('Failed to wipe existing directory ' . $this->directory . ' before copy');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function deleteIgnoredFiles()
|
||||||
|
{
|
||||||
if ($this->ignore) {
|
if ($this->ignore) {
|
||||||
foreach ($this->phpci->ignore as $file) {
|
foreach ($this->phpci->ignore as $file) {
|
||||||
$cmd = 'rm -Rf "%s/%s"';
|
$cmd = 'rm -Rf "%s/%s"';
|
||||||
|
@ -60,7 +83,5 @@ class CopyBuild implements \PHPCI\Plugin
|
||||||
$this->phpci->executeCommand($cmd, $this->directory, $file);
|
$this->phpci->executeCommand($cmd, $this->directory, $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $success;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue