Merge pull request #8607 from owncloud/filescan_app_hook
Allow apps to control via a hook skipping add/remove a file during filescan
This commit is contained in:
commit
da6aae28ad
|
@ -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
|
* 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
|
* 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,
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace OC\Files\Cache;
|
||||||
|
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Hooks\BasicEmitter;
|
use OC\Hooks\BasicEmitter;
|
||||||
|
use OCP\Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Scanner
|
* Class Scanner
|
||||||
|
@ -43,6 +44,11 @@ class Scanner extends BasicEmitter {
|
||||||
*/
|
*/
|
||||||
protected $permissionsCache;
|
protected $permissionsCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var boolean $cacheActive If true, perform cache operations, if false, do not affect cache
|
||||||
|
*/
|
||||||
|
protected $cacheActive;
|
||||||
|
|
||||||
const SCAN_RECURSIVE = true;
|
const SCAN_RECURSIVE = true;
|
||||||
const SCAN_SHALLOW = false;
|
const SCAN_SHALLOW = false;
|
||||||
|
|
||||||
|
@ -54,6 +60,7 @@ class Scanner extends BasicEmitter {
|
||||||
$this->storageId = $this->storage->getId();
|
$this->storageId = $this->storage->getId();
|
||||||
$this->cache = $storage->getCache();
|
$this->cache = $storage->getCache();
|
||||||
$this->permissionsCache = $storage->getPermissionsCache();
|
$this->permissionsCache = $storage->getPermissionsCache();
|
||||||
|
$this->cacheActive = !Config::getSystemValue('filesystem_cache_readonly', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,9 +144,12 @@ class Scanner extends BasicEmitter {
|
||||||
$parent = '';
|
$parent = '';
|
||||||
}
|
}
|
||||||
$parentCacheData = $this->cache->get($parent);
|
$parentCacheData = $this->cache->get($parent);
|
||||||
$this->cache->update($parentCacheData['fileid'], array(
|
\OC_Hook::emit('Scanner', 'updateCache', array('file' => $file, 'data' => $data));
|
||||||
'etag' => $this->storage->getETag($parent),
|
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)) {
|
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));
|
$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));
|
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', array('path' => $file, 'storage' => $this->storageId));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->cache->remove($file);
|
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
|
||||||
|
if($this->cacheActive) {
|
||||||
|
$this->cache->remove($file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -244,7 +260,10 @@ class Scanner extends BasicEmitter {
|
||||||
$removedChildren = \array_diff($existingChildren, $newChildren);
|
$removedChildren = \array_diff($existingChildren, $newChildren);
|
||||||
foreach ($removedChildren as $childName) {
|
foreach ($removedChildren as $childName) {
|
||||||
$child = ($path) ? $path . '/' . $childName : $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();
|
\OC_DB::commit();
|
||||||
if ($exceptionOccurred){
|
if ($exceptionOccurred){
|
||||||
|
@ -263,7 +282,11 @@ class Scanner extends BasicEmitter {
|
||||||
$size += $childSize;
|
$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));
|
$this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', array($path, $this->storageId));
|
||||||
return $size;
|
return $size;
|
||||||
|
@ -290,8 +313,19 @@ class Scanner extends BasicEmitter {
|
||||||
$lastPath = null;
|
$lastPath = null;
|
||||||
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
|
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
|
||||||
$this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
|
$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;
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue