From b5c68f2a02ed0eca57c6396c998d92ac89858f84 Mon Sep 17 00:00:00 2001 From: Batandwa Colani Date: Fri, 30 Sep 2016 00:25:52 +0200 Subject: [PATCH] Fixed incorrect removing directory contents when using symlinks. --- PHPCI/Model/Build.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PHPCI/Model/Build.php b/PHPCI/Model/Build.php index a8bfd683..396904cb 100644 --- a/PHPCI/Model/Build.php +++ b/PHPCI/Model/Build.php @@ -269,13 +269,20 @@ class Build extends BuildBase */ public function removeBuildDirectory() { - $buildPath = $this->getBuildPath(); + // Get the path and remove the trailing slash as this may prompt PHP + // to see this as a directory even if it's a link. + $buildPath = rtrim($this->getBuildPath(), '/'); if (!$buildPath || !is_dir($buildPath)) { return; } - exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm -Rf "%s"', $buildPath)); + if (is_link($buildPath)) { + // Remove the symlink without using recursive. + exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm "%s"', $buildPath)); + } else { + exec(sprintf(IS_WIN ? 'rmdir /S /Q "%s"' : 'rm -Rf "%s"', $buildPath)); + } } /**