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,6 +144,8 @@ class Scanner extends BasicEmitter {
|
||||||
$parent = '';
|
$parent = '';
|
||||||
}
|
}
|
||||||
$parentCacheData = $this->cache->get($parent);
|
$parentCacheData = $this->cache->get($parent);
|
||||||
|
\OC_Hook::emit('Scanner', 'updateCache', array('file' => $file, 'data' => $data));
|
||||||
|
if($this->cacheActive) {
|
||||||
$this->cache->update($parentCacheData['fileid'], array(
|
$this->cache->update($parentCacheData['fileid'], array(
|
||||||
'etag' => $this->storage->getETag($parent),
|
'etag' => $this->storage->getETag($parent),
|
||||||
));
|
));
|
||||||
|
@ -144,6 +153,7 @@ class Scanner extends BasicEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Only update metadata that has changed
|
// Only update metadata that has changed
|
||||||
$newData = array_diff_assoc($data, $cacheData);
|
$newData = array_diff_assoc($data, $cacheData);
|
||||||
if (isset($newData['etag'])) {
|
if (isset($newData['etag'])) {
|
||||||
|
@ -156,13 +166,19 @@ class Scanner extends BasicEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($newData)) {
|
if (!empty($newData)) {
|
||||||
|
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $file, 'data' => $newData));
|
||||||
|
if($this->cacheActive) {
|
||||||
$data['fileid'] = $this->cache->put($file, $newData);
|
$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 {
|
||||||
|
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
|
||||||
|
if($this->cacheActive) {
|
||||||
$this->cache->remove($file);
|
$this->cache->remove($file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -244,8 +260,11 @@ 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;
|
||||||
|
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $child));
|
||||||
|
if($this->cacheActive) {
|
||||||
$this->cache->remove($child);
|
$this->cache->remove($child);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
\OC_DB::commit();
|
\OC_DB::commit();
|
||||||
if ($exceptionOccurred){
|
if ($exceptionOccurred){
|
||||||
// It might happen that the parallel scan process has already
|
// It might happen that the parallel scan process has already
|
||||||
|
@ -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);
|
||||||
|
\OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
|
||||||
|
if($this->cacheActive) {
|
||||||
$this->cache->correctFolderSize($path);
|
$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