]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix cache update when doing a rename that overwrites the target
authorRobin Appelman <icewind@owncloud.com>
Fri, 27 Feb 2015 13:26:52 +0000 (14:26 +0100)
committerRobin Appelman <icewind@owncloud.com>
Fri, 27 Feb 2015 15:39:58 +0000 (16:39 +0100)
lib/private/files/cache/updater.php
tests/lib/files/view.php

index 9f4cbfeff8c5dc79fb06dd17e04c2e4a70f25740..eeb763921bb13a4ae9bc416bbd4319ee42986b2a 100644 (file)
@@ -45,7 +45,7 @@ class Updater {
         * @param int $time
         */
        public function update($path, $time = null) {
-               if(Scanner::isPartialFile($path)) {
+               if (Scanner::isPartialFile($path)) {
                        return;
                }
                /**
@@ -116,6 +116,9 @@ class Updater {
                if ($sourceStorage && $targetStorage) {
                        if ($sourceStorage === $targetStorage) {
                                $cache = $sourceStorage->getCache($sourceInternalPath);
+                               if ($cache->inCache($targetInternalPath)) {
+                                       $cache->remove($targetInternalPath);
+                               }
                                $cache->move($sourceInternalPath, $targetInternalPath);
 
                                if (pathinfo($sourceInternalPath, PATHINFO_EXTENSION) !== pathinfo($targetInternalPath, PATHINFO_EXTENSION)) {
index 0d88ec1d66a8607b130eac21acec1bd6fe023f26..db39df7d16bcb8610b79fccc985567546bd6f24b 100644 (file)
@@ -962,4 +962,17 @@ class View extends \Test\TestCase {
        public function testConstructDirectoryTraversalException($root) {
                new \OC\Files\View($root);
        }
+
+       public function testRenameOverWrite() {
+               $storage = new Temporary(array());
+               $scanner = $storage->getScanner();
+               $storage->mkdir('sub');
+               $storage->mkdir('foo');
+               $storage->file_put_contents('foo.txt', 'asd');
+               $storage->file_put_contents('foo/bar.txt', 'asd');
+               $scanner->scan('');
+               \OC\Files\Filesystem::mount($storage, array(), '/test/');
+               $view = new \OC\Files\View('');
+               $this->assertTrue($view->rename('/test/foo.txt', '/test/foo/bar.txt'));
+       }
 }