]> source.dussan.org Git - nextcloud-server.git/commitdiff
Dont remove a file from cache if the delete operation failed
authorRobin Appelman <icewind@owncloud.com>
Tue, 20 Jan 2015 11:59:57 +0000 (12:59 +0100)
committerRobin Appelman <icewind@owncloud.com>
Thu, 29 Jan 2015 14:39:56 +0000 (15:39 +0100)
lib/private/files/view.php
tests/lib/files/view.php

index a2717ce43212f4dd8bef11043799708be9cf424b..5ed7af9222c8257547bd5afeabefb945fd6fe901 100644 (file)
@@ -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)) {
index 5e42e5ffd0fd959e4fdb8e271decea473cb7e0f1..9ddc9c804754259c6f3a764a6b6553236db1796e 100644 (file)
@@ -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'));
+       }
 }