parent
58b6b89ec4
commit
a908e281e7
|
@ -254,4 +254,7 @@ $CONFIG = array(
|
|||
|
||||
/* whether usage of the instance should be restricted to admin users only */
|
||||
'singleuser' => false,
|
||||
|
||||
/* 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\Hooks\BasicEmitter;
|
||||
use OCP\Config;
|
||||
|
||||
/**
|
||||
* Class Scanner
|
||||
|
@ -43,6 +44,11 @@ class Scanner extends BasicEmitter {
|
|||
*/
|
||||
private $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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -136,6 +143,8 @@ class Scanner extends BasicEmitter {
|
|||
$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(
|
||||
'etag' => $this->storage->getETag($parent),
|
||||
));
|
||||
|
@ -143,6 +152,7 @@ class Scanner extends BasicEmitter {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only update metadata that has changed
|
||||
$newData = array_diff_assoc($data, $cacheData);
|
||||
if (isset($newData['etag'])) {
|
||||
|
@ -155,13 +165,19 @@ class Scanner extends BasicEmitter {
|
|||
}
|
||||
}
|
||||
if (!empty($newData)) {
|
||||
$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 {
|
||||
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
|
||||
if($this->cacheActive) {
|
||||
$this->cache->remove($file);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return null;
|
||||
|
@ -241,8 +257,11 @@ class Scanner extends BasicEmitter {
|
|||
$removedChildren = \array_diff($existingChildren, $newChildren);
|
||||
foreach ($removedChildren as $childName) {
|
||||
$child = ($path) ? $path . '/' . $childName : $childName;
|
||||
\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $child));
|
||||
if($this->cacheActive) {
|
||||
$this->cache->remove($child);
|
||||
}
|
||||
}
|
||||
\OC_DB::commit();
|
||||
if ($exceptionOccurred){
|
||||
// It might happen that the parallel scan process has already
|
||||
|
@ -260,7 +279,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;
|
||||
|
@ -287,8 +310,19 @@ class Scanner extends BasicEmitter {
|
|||
$lastPath = null;
|
||||
while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
|
||||
$this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
|
||||
\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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue