]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix moving folders out of a cache jail
authorRobin Appelman <robin@icewind.nl>
Thu, 15 Jun 2017 11:59:06 +0000 (13:59 +0200)
committerRobin Appelman <robin@icewind.nl>
Thu, 13 Jul 2017 11:08:23 +0000 (13:08 +0200)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Cache/Wrapper/CacheJail.php
tests/lib/Files/Cache/Wrapper/CacheJailTest.php

index ebab20fbaedb19b1a76ce50d21688ccbecabb543..8f12ca77ee668e0c5539d045b1418ebae3d261c2 100644 (file)
@@ -94,7 +94,7 @@ class CacheJail extends CacheWrapper {
         * get the stored metadata of a file or folder
         *
         * @param string /int $file
-        * @return array|false
+        * @return ICacheEntry|false
         */
        public function get($file) {
                if (is_string($file) or $file == '') {
@@ -175,6 +175,16 @@ class CacheJail extends CacheWrapper {
                $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
        }
 
+       /**
+        * Get the storage id and path needed for a move
+        *
+        * @param string $path
+        * @return array [$storageId, $internalPath]
+        */
+       protected function getMoveInfo($path) {
+               return [$this->getNumericStorageId(), $this->getSourcePath($path)];
+       }
+
        /**
         * remove all entries for files that are stored on the storage from the cache
         */
index e3043c50d57688a7c581a8a8f0bf94d1f3a3e90f..f26e3a59f1c28ed0d792ee520247891c71165f21 100644 (file)
@@ -8,6 +8,7 @@
 
 namespace Test\Files\Cache\Wrapper;
 
+use OC\Files\Cache\Wrapper\CacheJail;
 use Test\Files\Cache\CacheTest;
 
 /**
@@ -80,4 +81,53 @@ class CacheJailTest extends CacheTest {
                //not supported
                $this->assertTrue(true);
        }
+
+       function testMoveFromJail() {
+               $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+               $this->sourceCache->put('source', $folderData);
+               $this->sourceCache->put('source/foo', $folderData);
+               $this->sourceCache->put('source/foo/bar', $folderData);
+               $this->sourceCache->put('target', $folderData);
+
+               $jail = new CacheJail($this->sourceCache, 'source');
+
+               $this->sourceCache->moveFromCache($jail, 'foo', 'target/foo');
+
+               $this->assertTrue($this->sourceCache->inCache('target/foo'));
+               $this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
+       }
+
+       function testMoveToJail() {
+               $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+               $this->sourceCache->put('source', $folderData);
+               $this->sourceCache->put('source/foo', $folderData);
+               $this->sourceCache->put('source/foo/bar', $folderData);
+               $this->sourceCache->put('target', $folderData);
+
+               $jail = new CacheJail($this->sourceCache, 'target');
+
+               $jail->moveFromCache($this->sourceCache, 'source/foo', 'foo');
+
+               $this->assertTrue($this->sourceCache->inCache('target/foo'));
+               $this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
+       }
+
+       function testMoveBetweenJail() {
+               $folderData = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+               $this->sourceCache->put('source', $folderData);
+               $this->sourceCache->put('source/foo', $folderData);
+               $this->sourceCache->put('source/foo/bar', $folderData);
+               $this->sourceCache->put('target', $folderData);
+
+               $jail = new CacheJail($this->sourceCache, 'target');
+               $sourceJail = new CacheJail($this->sourceCache, 'source');
+
+               $jail->moveFromCache($sourceJail, 'foo', 'foo');
+
+               $this->assertTrue($this->sourceCache->inCache('target/foo'));
+               $this->assertTrue($this->sourceCache->inCache('target/foo/bar'));
+       }
 }