From e4db6efaf3c91033e1ff19955b83aa1dd9495d4b Mon Sep 17 00:00:00 2001 From: Batandwa Date: Sat, 24 Dec 2016 17:17:52 +0700 Subject: [PATCH] Fixed incorrect removing directory contents when using symlinks. --- src/PHPCensor/Model/Build.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 8c7b1e78..2823ef23 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -270,13 +270,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)); + } } /**