summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Winkler <a_github@midnightcircus.com>2014-05-30 12:38:37 -0400
committerOwen Winkler <a_github@midnightcircus.com>2014-05-30 12:38:37 -0400
commitda6aae28ad0cb1bad3d0693f126a5436af64240d (patch)
tree912b952a2303bff189a2e8826460647fa04f3285
parentb7f163a701e7c42fafac13477313636ba771e31a (diff)
parent19f0c47842527d565df3383a2c65830df3f3274f (diff)
downloadnextcloud-server-da6aae28ad0cb1bad3d0693f126a5436af64240d.tar.gz
nextcloud-server-da6aae28ad0cb1bad3d0693f126a5436af64240d.zip
Merge pull request #8607 from owncloud/filescan_app_hook
Allow apps to control via a hook skipping add/remove a file during filescan
-rwxr-xr-xconfig/config.sample.php5
-rw-r--r--lib/private/files/cache/scanner.php50
2 files changed, 46 insertions, 9 deletions
diff --git a/config/config.sample.php b/config/config.sample.php
index 590aba714eb..0a81543589b 100755
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -297,6 +297,9 @@ $CONFIG = array(
* 1 -> check each file or folder at most once per request, recomended for general use if outside changes might happen
* 2 -> check every time the filesystem is used, causes a performance hit when using external storages, not recomended for regular use
*/
-'filesystem_check_changes' => 1
+'filesystem_check_changes' => 1,
+
+/* If true, prevent owncloud from changing the cache due to changes in the filesystem for all storage */
+'filesystem_cache_readonly' => false,
);
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index 61b22ea75a0..b97070fcdf0 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -10,6 +10,7 @@ namespace OC\Files\Cache;
use OC\Files\Filesystem;
use OC\Hooks\BasicEmitter;
+use OCP\Config;
/**
* Class Scanner
@@ -43,6 +44,11 @@ class Scanner extends BasicEmitter {
*/
protected $permissionsCache;
+ /**
+ * @var boolean $cacheActive If true, perform cache operations, if false, do not affect cache
+ */
+ protected $cacheActive;
+
const SCAN_RECURSIVE = true;
const SCAN_SHALLOW = false;
@@ -54,6 +60,7 @@ class Scanner extends BasicEmitter {
$this->storageId = $this->storage->getId();
$this->cache = $storage->getCache();
$this->permissionsCache = $storage->getPermissionsCache();
+ $this->cacheActive = !Config::getSystemValue('filesystem_cache_readonly', false);
}
/**
@@ -137,9 +144,12 @@ class Scanner extends BasicEmitter {
$parent = '';
}
$parentCacheData = $this->cache->get($parent);
- $this->cache->update($parentCacheData['fileid'], array(
- 'etag' => $this->storage->getETag($parent),
- ));
+ \OC_Hook::emit('Scanner', 'updateCache', array('file' => $file, 'data' => $data));
+ if($this->cacheActive) {
+ $this->cache->update($parentCacheData['fileid'], array(
+ 'etag' => $this->storage->getETag($parent),
+ ));
+ }
}
}
}
@@ -156,12 +166,18 @@ class Scanner extends BasicEmitter {
}
}
if (!empty($newData)) {
- $data['fileid'] = $this->cache->put($file, $newData);
+ \OC_Hook::emit('Scanner', 'addToCache', array('file' => $file, 'data' => $newData));
+ if($this->cacheActive) {
+ $data['fileid'] = $this->cache->put($file, $newData);
+ }
$this->emit('\OC\Files\Cache\Scanner', 'postScanFile', array($file, $this->storageId));
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', array('path' => $file, 'storage' => $this->storageId));
}
} else {
- $this->cache->remove($file);
+ \OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
+ if($this->cacheActive) {
+ $this->cache->remove($file);
+ }
}
return $data;
}
@@ -244,7 +260,10 @@ class Scanner extends BasicEmitter {
$removedChildren = \array_diff($existingChildren, $newChildren);
foreach ($removedChildren as $childName) {
$child = ($path) ? $path . '/' . $childName : $childName;
- $this->cache->remove($child);
+ \OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $child));
+ if($this->cacheActive) {
+ $this->cache->remove($child);
+ }
}
\OC_DB::commit();
if ($exceptionOccurred){
@@ -263,7 +282,11 @@ class Scanner extends BasicEmitter {
$size += $childSize;
}
}
- $this->cache->put($path, array('size' => $size));
+ $newData = array('size' => $size);
+ \OC_Hook::emit('Scanner', 'addToCache', array('file' => $child, 'data' => $newData));
+ if($this->cacheActive) {
+ $this->cache->put($path, $newData);
+ }
}
$this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', array($path, $this->storageId));
return $size;
@@ -290,8 +313,19 @@ class Scanner extends BasicEmitter {
$lastPath = null;
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
$this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
- $this->cache->correctFolderSize($path);
+ \OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
+ if($this->cacheActive) {
+ $this->cache->correctFolderSize($path);
+ }
$lastPath = $path;
}
}
+
+ /**
+ * Set whether the cache is affected by scan operations
+ * @param boolean $active The active state of the cache
+ */
+ public function setCacheActive($active) {
+ $this->cacheActive = $active;
+ }
}