From 2124540d1d9f500423e5149b1490ed489788ff1d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 20 Jan 2015 12:59:57 +0100 Subject: [PATCH] Dont remove a file from cache if the delete operation failed --- lib/private/files/view.php | 2 +- tests/lib/files/view.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/private/files/view.php b/lib/private/files/view.php index a2717ce4321..5ed7af9222c 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -803,7 +803,7 @@ class View { $result = \OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result); - if (in_array('delete', $hooks)) { + if (in_array('delete', $hooks) and $result) { $this->updater->remove($path); } if (in_array('write', $hooks)) { diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 5e42e5ffd0f..9ddc9c80475 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -849,4 +849,27 @@ class View extends \Test\TestCase { $this->assertEquals($time, $view->filemtime('/test/sub/storage/foo/bar.txt')); } + + public function testDeleteFailKeepCache() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Files\Storage\Temporary $storage + */ + $storage = $this->getMockBuilder('\OC\Files\Storage\Temporary') + ->setConstructorArgs(array(array())) + ->setMethods(array('unlink')) + ->getMock(); + $storage->expects($this->once()) + ->method('unlink') + ->will($this->returnValue(false)); + $scanner = $storage->getScanner(); + $cache = $storage->getCache(); + $storage->file_put_contents('foo.txt', 'asd'); + $scanner->scan(''); + \OC\Files\Filesystem::mount($storage, array(), '/test/'); + + $view = new \OC\Files\View('/test'); + + $this->assertFalse($view->unlink('foo.txt')); + $this->assertTrue($cache->inCache('foo.txt')); + } } -- 2.39.5