Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 3872705

Browse files
author
Michael Grauer
committed
BUG: Refs #212. Improved error handling in recursiveRemoveDirectory, and tests
1 parent 3c4ba70 commit 3872705

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

library/KWUtils.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ public static function formatAppName($app_name)
284284
*/
285285
public static function recursiveRemoveDirectory($directorypath)
286286
{
287+
if(empty($directorypath) || !is_dir($directorypath))
288+
{
289+
return false;
290+
}
287291
// if the path has a slash at the end, remove it here
288292
$directorypath = rtrim($directorypath, '/');
289293
// open the directory
@@ -324,5 +328,4 @@ public static function recursiveRemoveDirectory($directorypath)
324328
return true;
325329
}
326330

327-
328331
}

tests/library/KWUtilsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public function testPrepareExecCommand()
156156
/** tests recursiveRemoveDirectory function */
157157
public function testRecursiveRemoveDirectory()
158158
{
159+
// test some basic exception handling
160+
$this->assertFalse(KWUtils::recursiveRemoveDirectory(''));
161+
$this->assertFalse(KWUtils::recursiveRemoveDirectory('thisstringisunlikelytobeadirectory'));
162+
159163
// create a two-level directory
160164
$testParentDir = $this->getTempDirectory() . '/KWUtilsParentDir';
161165
mkdir($testParentDir);

0 commit comments

Comments
 (0)