]> source.dussan.org Git - nextcloud-server.git/commitdiff
clear permissions cache when scanning a file
authorRobin Appelman <icewind@owncloud.com>
Thu, 19 Sep 2013 19:37:52 +0000 (21:37 +0200)
committerAndreas Fischer <bantu@owncloud.com>
Mon, 23 Sep 2013 22:57:58 +0000 (00:57 +0200)
lib/files/cache/scanner.php
tests/lib/files/cache/permissions.php

index a986c1ca72523ec10cf1da3db1bb24e216dacb53..af819c47c6187255e8f820daa0c640959a09fe49 100644 (file)
@@ -36,6 +36,11 @@ class Scanner extends BasicEmitter {
         */
        private $cache;
 
+       /**
+        * @var \OC\Files\Cache\Permissions $permissionsCache
+        */
+       private $permissionsCache;
+
        const SCAN_RECURSIVE = true;
        const SCAN_SHALLOW = false;
 
@@ -46,6 +51,7 @@ class Scanner extends BasicEmitter {
                $this->storage = $storage;
                $this->storageId = $this->storage->getId();
                $this->cache = $storage->getCache();
+               $this->permissionsCache = $storage->getPermissionsCache();
        }
 
        /**
@@ -96,7 +102,11 @@ class Scanner extends BasicEmitter {
                                        }
                                }
                                $newData = $data;
-                               if ($reuseExisting and $cacheData = $this->cache->get($file)) {
+                               $cacheData = $this->cache->get($file);
+                               if ($cacheData) {
+                                       $this->permissionsCache->remove($cacheData['fileid']);
+                               }
+                               if ($reuseExisting and $cacheData) {
                                        // prevent empty etag
                                        $etag = $cacheData['etag'];
                                        $propagateETagChange = false;
@@ -104,7 +114,6 @@ class Scanner extends BasicEmitter {
                                                $etag = $data['etag'];
                                                $propagateETagChange = true;
                                        }
-
                                        // only reuse data if the file hasn't explicitly changed
                                        if (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) {
                                                if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) {
@@ -182,7 +191,7 @@ class Scanner extends BasicEmitter {
                $newChildren = array();
                if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
                        \OC_DB::beginTransaction();
-                       if(is_resource($dh)) {
+                       if (is_resource($dh)) {
                                while (($file = readdir($dh)) !== false) {
                                        $child = ($path) ? $path . '/' . $file : $file;
                                        if (!Filesystem::isIgnoredDir($file)) {
index 7e6e11e2eb29c09e6fe9a5fdcf2dd293f7e82c98..4b284c2c8e287f6bdaf87cd8b24d1f95e27e20a5 100644 (file)
@@ -8,6 +8,8 @@
 
 namespace Test\Files\Cache;
 
+use OC\Files\Storage\Temporary;
+
 class Permissions extends \PHPUnit_Framework_TestCase {
        /***
         * @var \OC\Files\Cache\Permissions $permissionsCache
@@ -55,4 +57,19 @@ class Permissions extends \PHPUnit_Framework_TestCase {
 
                $this->permissionsCache->removeMultiple($ids, $user);
        }
+
+       public function testUpdatePermissionsOnRescan() {
+               $storage = new Temporary(array());
+               $scanner = $storage->getScanner();
+               $cache = $storage->getCache();
+               $permissionsCache = $storage->getPermissionsCache();
+
+               $storage->file_put_contents('foo.txt', 'bar');
+               $scanner->scan('');
+               $id = $cache->getId('foo.txt');
+               $permissionsCache->set($id, 'test', 1);
+
+               $scanner->scan('');
+               $this->assertEquals(-1, $permissionsCache->get($id, 'test'));
+       }
 }