Commit 41ef8e31 authored by Vincent Petry's avatar Vincent Petry Committed by Thomas Müller
Browse files

Redirect unlink to rmdir (#27101)

Many API callers will call unlink even for directories and it can mess
up with some wrappers like the encryption wrapper
parent 45d9a3ae
......@@ -686,7 +686,11 @@ class View {
if ($mount and $mount->getInternalPath($absolutePath) === '') {
return $this->removeMount($mount, $absolutePath);
}
$result = $this->basicOperation('unlink', $path, ['delete']);
if ($this->is_dir($path)) {
$result = $this->basicOperation('rmdir', $path, array('delete'));
} else {
$result = $this->basicOperation('unlink', $path, array('delete'));
}
if (!$result && !$this->file_exists($path)) { //clear ghost files from the cache on delete
$storage = $mount->getStorage();
$internalPath = $mount->getInternalPath($absolutePath);
......
......@@ -516,6 +516,30 @@ class ViewTest extends 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
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment