summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Files/View.php6
-rw-r--r--tests/lib/Files/ViewTest.php24
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index db21d400b39..6ffb5edff3e 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -692,7 +692,11 @@ class View {
if ($mount and $mount->getInternalPath($absolutePath) === '') {
return $this->removeMount($mount, $absolutePath);
}
- $result = $this->basicOperation('unlink', $path, array('delete'));
+ if ($this->is_dir($path)) {
+ $result = $this->basicOperation('rmdir', $path, ['delete']);
+ } else {
+ $result = $this->basicOperation('unlink', $path, ['delete']);
+ }
if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($absolutePath);
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index 8ec9619087c..4cdea59da0d 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -515,6 +515,30 @@ class ViewTest extends \Test\TestCase {
$this->assertFalse($rootView->file_exists('substorage/bar.txt'));
}
+ public function rmdirOrUnlinkDataProvider() {
+ return [['rmdir'], ['unlink']];
+ }
+
+ /**
+ * @dataProvider rmdirOrUnlinkDataProvider
+ */
+ public function testRmdir($method) {
+ $storage1 = $this->getTestStorage();
+ $storage2 = $this->getTestStorage();
+ Filesystem::mount($storage1, [], '/');
+
+ $rootView = new View('');
+ $rootView->mkdir('sub');
+ $rootView->mkdir('sub/deep');
+ $rootView->file_put_contents('/sub/deep/foo.txt', 'asd');
+
+ $this->assertTrue($rootView->file_exists('sub/deep/foo.txt'));
+
+ $this->assertTrue($rootView->$method('sub'));
+
+ $this->assertFalse($rootView->file_exists('sub'));
+ }
+
/**
* @medium
*/