|
|
|
|
@ -36,6 +36,11 @@ class Scanner extends BasicEmitter { |
|
|
|
|
*/ |
|
|
|
|
private $cache; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @var \OC\Files\Cache\Permissions $permissionsCache |
|
|
|
|
*/ |
|
|
|
|
private $permissionsCache; |
|
|
|
|
|
|
|
|
|
const SCAN_RECURSIVE = true; |
|
|
|
|
const SCAN_SHALLOW = false; |
|
|
|
|
|
|
|
|
|
@ -46,6 +51,7 @@ class Scanner extends BasicEmitter { |
|
|
|
|
$this->storage = $storage; |
|
|
|
|
$this->storageId = $this->storage->getId(); |
|
|
|
|
$this->cache = $storage->getCache(); |
|
|
|
|
$this->permissionsCache = $storage->getPermissionsCache(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -96,39 +102,42 @@ class Scanner extends BasicEmitter { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$newData = $data; |
|
|
|
|
if ($reuseExisting and $cacheData = $this->cache->get($file)) { |
|
|
|
|
// prevent empty etag |
|
|
|
|
$etag = $cacheData['etag']; |
|
|
|
|
$propagateETagChange = false; |
|
|
|
|
if (empty($etag)) { |
|
|
|
|
$etag = $data['etag']; |
|
|
|
|
$propagateETagChange = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// only reuse data if the file hasn't explicitly changed |
|
|
|
|
if (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) { |
|
|
|
|
if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) { |
|
|
|
|
$data['size'] = $cacheData['size']; |
|
|
|
|
$cacheData = $this->cache->get($file); |
|
|
|
|
if ($cacheData) { |
|
|
|
|
$this->permissionsCache->remove($cacheData['fileid']); |
|
|
|
|
if ($reuseExisting) { |
|
|
|
|
// prevent empty etag |
|
|
|
|
$etag = $cacheData['etag']; |
|
|
|
|
$propagateETagChange = false; |
|
|
|
|
if (empty($etag)) { |
|
|
|
|
$etag = $data['etag']; |
|
|
|
|
$propagateETagChange = true; |
|
|
|
|
} |
|
|
|
|
if ($reuseExisting & self::REUSE_ETAG) { |
|
|
|
|
$data['etag'] = $etag; |
|
|
|
|
if ($propagateETagChange) { |
|
|
|
|
$parent = $file; |
|
|
|
|
while ($parent !== '') { |
|
|
|
|
$parent = dirname($parent); |
|
|
|
|
if ($parent === '.') { |
|
|
|
|
$parent = ''; |
|
|
|
|
// only reuse data if the file hasn't explicitly changed |
|
|
|
|
if (isset($data['mtime']) && isset($cacheData['mtime']) && $data['mtime'] === $cacheData['mtime']) { |
|
|
|
|
if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) { |
|
|
|
|
$data['size'] = $cacheData['size']; |
|
|
|
|
} |
|
|
|
|
if ($reuseExisting & self::REUSE_ETAG) { |
|
|
|
|
$data['etag'] = $etag; |
|
|
|
|
if ($propagateETagChange) { |
|
|
|
|
$parent = $file; |
|
|
|
|
while ($parent !== '') { |
|
|
|
|
$parent = dirname($parent); |
|
|
|
|
if ($parent === '.') { |
|
|
|
|
$parent = ''; |
|
|
|
|
} |
|
|
|
|
$parentCacheData = $this->cache->get($parent); |
|
|
|
|
$this->cache->update($parentCacheData['fileid'], array( |
|
|
|
|
'etag' => $this->storage->getETag($parent), |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
$parentCacheData = $this->cache->get($parent); |
|
|
|
|
$this->cache->update($parentCacheData['fileid'], array( |
|
|
|
|
'etag' => $this->storage->getETag($parent), |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Only update metadata that has changed |
|
|
|
|
$newData = array_diff($data, $cacheData); |
|
|
|
|
} |
|
|
|
|
// Only update metadata that has changed |
|
|
|
|
$newData = array_diff($data, $cacheData); |
|
|
|
|
} |
|
|
|
|
if (!empty($newData)) { |
|
|
|
|
$this->cache->put($file, $newData); |
|
|
|
|
@ -182,7 +191,7 @@ class Scanner extends BasicEmitter { |
|
|
|
|
$newChildren = array(); |
|
|
|
|
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) { |
|
|
|
|
\OC_DB::beginTransaction(); |
|
|
|
|
if(is_resource($dh)) { |
|
|
|
|
if (is_resource($dh)) { |
|
|
|
|
while (($file = readdir($dh)) !== false) { |
|
|
|
|
$child = ($path) ? $path . '/' . $file : $file; |
|
|
|
|
if (!Filesystem::isIgnoredDir($file)) { |
|
|
|
|
|