diff --git a/wire/core/WireFileTools.php b/wire/core/WireFileTools.php index e51be2bb..6e66cde5 100644 --- a/wire/core/WireFileTools.php +++ b/wire/core/WireFileTools.php @@ -104,7 +104,7 @@ class WireFileTools extends Wire { $files = @scandir($path); if(is_array($files)) foreach($files as $file) { if($file == '.' || $file == '..' || strpos($file, '..') !== false) continue; - $pathname = "$path/$file"; + $pathname = rtrim($path, '/') . '/' . $file; if(is_dir($pathname)) { $this->rmdir($pathname, $recursive, $options); } else { diff --git a/wire/core/WireTempDir.php b/wire/core/WireTempDir.php index 6e29d696..8a999266 100644 --- a/wire/core/WireTempDir.php +++ b/wire/core/WireTempDir.php @@ -276,7 +276,7 @@ class WireTempDir extends Wire { } } - if(!$numSubdirs) { + if(!$numSubdirs && $path != $this->classRoot && $this->isTempDir($path)) { // if no subdirectories, we can remove the root if($this->rmdir($path, true)) { $success = true; @@ -381,10 +381,13 @@ class WireTempDir extends Wire { * */ protected function isTempDir($dir) { + $files = $this->wire('files'); if(!strlen($dir) || !is_dir($dir)) { // if given a non-directory return false return false; - } else if($this->classRoot && $this->wire('files')->fileInPath($dir, $this->classRoot)) { + } + if($this->classRoot && $files->fileInPath($dir, $this->classRoot)) { + // dir is within classRoot path return true; } return false;