summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-09-24 00:50:33 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-09-24 00:50:33 -0700
commit759f732aaaea7eb2fcb57175514489631923b094 (patch)
treee3aa4fad1b40fab638e085c044cb25f25aa4587a
parentbc1c6039b798c9460b8bbb8ef24b0f2d12229810 (diff)
parent21299745846eaa87988dcc5acd6f5604b363b03e (diff)
downloadnextcloud-server-759f732aaaea7eb2fcb57175514489631923b094.tar.gz
nextcloud-server-759f732aaaea7eb2fcb57175514489631923b094.zip
Merge pull request #4917 from owncloud/scan-clear-permissions
clear permissions cache when scanning a file
-rw-r--r--lib/files/cache/scanner.php65
-rw-r--r--tests/lib/files/cache/permissions.php17
2 files changed, 54 insertions, 28 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index a986c1ca725..96f84609cf2 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -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,39 +102,42 @@ class Scanner extends BasicEmitter {
}
}
$newData = $data;
- if ($reuseExisting and $cacheData = $this->cache->get($file)) {
- // prevent empty etag
- $etag = $cacheData['etag'];
- $propagateETagChange = false;
- if (empty($etag)) {
- $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)) {
- $data['size'] = $cacheData['size'];
+ $cacheData = $this->cache->get($file);
+ if ($cacheData) {
+ $this->permissionsCache->remove($cacheData['fileid']);
+ if ($reuseExisting) {
+ // prevent empty etag
+ $etag = $cacheData['etag'];
+ $propagateETagChange = false;
+ if (empty($etag)) {
+ $etag = $data['etag'];
+ $propagateETagChange = true;
}
- if ($reuseExisting & self::REUSE_ETAG) {
- $data['etag'] = $etag;
- if ($propagateETagChange) {
- $parent = $file;
- while ($parent !== '') {
- $parent = dirname($parent);
- if ($parent === '.') {
- $parent = '';
+ // 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)) {
+ $data['size'] = $cacheData['size'];
+ }
+ if ($reuseExisting & self::REUSE_ETAG) {
+ $data['etag'] = $etag;
+ if ($propagateETagChange) {
+ $parent = $file;
+ while ($parent !== '') {
+ $parent = dirname($parent);
+ if ($parent === '.') {
+ $parent = '';
+ }
+ $parentCacheData = $this->cache->get($parent);
+ $this->cache->update($parentCacheData['fileid'], array(
+ 'etag' => $this->storage->getETag($parent),
+ ));
}
- $parentCacheData = $this->cache->get($parent);
- $this->cache->update($parentCacheData['fileid'], array(
- 'etag' => $this->storage->getETag($parent),
- ));
}
}
}
+ // Only update metadata that has changed
+ $newData = array_diff($data, $cacheData);
}
- // Only update metadata that has changed
- $newData = array_diff($data, $cacheData);
}
if (!empty($newData)) {
$this->cache->put($file, $newData);
@@ -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)) {
diff --git a/tests/lib/files/cache/permissions.php b/tests/lib/files/cache/permissions.php
index 7e6e11e2eb2..4b284c2c8e2 100644
--- a/tests/lib/files/cache/permissions.php
+++ b/tests/lib/files/cache/permissions.php
@@ -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'));
+ }
}