Updates per comments on PR:
* Use "filesystem_cache_readonly" config setting, update comment in config.sample * Use $this->cacheActive to cache config setting * Add public Scanner::setCacheActive() to set $cacheActive programmatically
This commit is contained in:
parent
f79948f519
commit
16ae63bdfd
|
@ -293,7 +293,7 @@ $CONFIG = array(
|
||||||
*/
|
*/
|
||||||
'filesystem_check_changes' => 1,
|
'filesystem_check_changes' => 1,
|
||||||
|
|
||||||
/* specifies whether changes in the filesystem outside of owncloud affect cached data about those files */
|
/* If true, prevent owncloud from changing the cache due to changes in the filesystem for all storage */
|
||||||
'filesystem_check_enable' => 1,
|
'filesystem_cache_readonly' => false,
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
|
@ -44,6 +44,11 @@ class Scanner extends BasicEmitter {
|
||||||
*/
|
*/
|
||||||
private $permissionsCache;
|
private $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;
|
||||||
|
|
||||||
|
@ -55,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,7 +145,7 @@ class Scanner extends BasicEmitter {
|
||||||
}
|
}
|
||||||
$parentCacheData = $this->cache->get($parent);
|
$parentCacheData = $this->cache->get($parent);
|
||||||
\OC_Hook::emit('Scanner', 'updateCache', array('file' => $file, 'data' => $data));
|
\OC_Hook::emit('Scanner', 'updateCache', array('file' => $file, 'data' => $data));
|
||||||
if(Config::getSystemValue('filesystem_check_enable', true)) {
|
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),
|
||||||
));
|
));
|
||||||
|
@ -161,7 +167,7 @@ class Scanner extends BasicEmitter {
|
||||||
}
|
}
|
||||||
if (!empty($newData)) {
|
if (!empty($newData)) {
|
||||||
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $file, 'data' => $newData));
|
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $file, 'data' => $newData));
|
||||||
if(Config::getSystemValue('filesystem_check_enable', true)) {
|
if(!Config::getSystemValue('filesystem_cache_readonly', false)) {
|
||||||
$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));
|
||||||
|
@ -169,7 +175,7 @@ class Scanner extends BasicEmitter {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
|
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
|
||||||
if(Config::getSystemValue('filesystem_check_enable', true)) {
|
if($this->cacheActive) {
|
||||||
$this->cache->remove($file);
|
$this->cache->remove($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,7 +261,7 @@ class Scanner extends BasicEmitter {
|
||||||
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));
|
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $child));
|
||||||
if(Config::getSystemValue('filesystem_check_enable', true)) {
|
if($this->cacheActive) {
|
||||||
$this->cache->remove($child);
|
$this->cache->remove($child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +284,7 @@ class Scanner extends BasicEmitter {
|
||||||
}
|
}
|
||||||
$newData = array('size' => $size);
|
$newData = array('size' => $size);
|
||||||
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $child, 'data' => $newData));
|
\OC_Hook::emit('Scanner', 'addToCache', array('file' => $child, 'data' => $newData));
|
||||||
if(Config::getSystemValue('filesystem_check_enable', true)) {
|
if($this->cacheActive) {
|
||||||
$this->cache->put($path, $newData);
|
$this->cache->put($path, $newData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,10 +314,18 @@ class Scanner extends BasicEmitter {
|
||||||
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));
|
\OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
|
||||||
if(Config::getSystemValue('filesystem_check_enable', true)) {
|
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