summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-01-06 21:15:50 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-01-06 21:15:50 +0100
commitd8cf4dd43ecd37c371acf9bc6c17998b65d42ba4 (patch)
tree5cc8b8f21afdf6711746dc00dfdccce0f119257f
parentebec603febbe7426fbb12cbb4fd3cb42128fcbf8 (diff)
downloadrpg-d8cf4dd43ecd37c371acf9bc6c17998b65d42ba4.tar.gz
rpg-d8cf4dd43ecd37c371acf9bc6c17998b65d42ba4.tar.bz2
treat non-existing files as success on delete
-rw-r--r--_test/tests/inc/io_rmdir.test.php60
-rw-r--r--inc/io.php1
2 files changed, 61 insertions, 0 deletions
diff --git a/_test/tests/inc/io_rmdir.test.php b/_test/tests/inc/io_rmdir.test.php
index 9a122d111..3de57fa86 100644
--- a/_test/tests/inc/io_rmdir.test.php
+++ b/_test/tests/inc/io_rmdir.test.php
@@ -2,6 +2,66 @@
class io_rmdir_test extends DokuWikiTest {
+ function test_nopes(){
+ // set up test dir
+ $dir = io_mktmpdir();
+ $top = dirname($dir);
+ $this->assertTrue($dir !== false);
+ $this->assertTrue(is_dir($dir));
+
+ // switch into it
+ $this->assertTrue(chdir($dir));
+ $this->assertEquals($dir, getcwd());
+
+
+ $this->assertFalse(io_rmdir('', false));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFalse(io_rmdir('', true));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFalse(io_rmdir(null, false));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFalse(io_rmdir(null, true));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFalse(io_rmdir(false, false));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFalse(io_rmdir(false, true));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFalse(io_rmdir(array(), false));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFalse(io_rmdir(array(), true));
+ clearstatcache();
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+
+ $this->assertFileNotExists("$dir/this/does/not/exist");
+ $this->assertTrue(io_rmdir("$dir/this/does/not/exist"));
+ clearstatcache();
+ $this->assertFileNotExists("$dir/this/does/not/exist");
+ $this->assertTrue(is_dir($dir));
+ $this->assertTrue(is_dir($top));
+ }
+
function test_empty_single(){
// set up test dir
diff --git a/inc/io.php b/inc/io.php
index 30f34ad3c..892f93759 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -410,6 +410,7 @@ function io_mkdir_p($target){
*/
function io_rmdir($path, $removefiles = false) {
if(!is_string($path) || $path == "") return false;
+ if(!file_exists($path)) return true; // it's already gone or was never there, count as success
if(is_dir($path) && !is_link($path)) {
$dirs = array();