Skip to content
Snippets Groups Projects
Commit 251b676a authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #1616 from owncloud/cache_fixes_rebase

Cache: reuse known folder sizes when doing a shallow scan - rebase
parents 8d9352a4 b54dcd19
Branches
No related tags found
No related merge requests found
...@@ -58,9 +58,10 @@ class Scanner { ...@@ -58,9 +58,10 @@ class Scanner {
* scan a single file and store it in the cache * scan a single file and store it in the cache
* *
* @param string $file * @param string $file
* @param bool $checkExisting check existing folder sizes in the cache instead of always using -1 for folder size
* @return array with metadata of the scanned file * @return array with metadata of the scanned file
*/ */
public function scanFile($file) { public function scanFile($file, $checkExisting = false) {
\OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId)); \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
$data = $this->getData($file); $data = $this->getData($file);
if ($data) { if ($data) {
...@@ -73,7 +74,15 @@ class Scanner { ...@@ -73,7 +74,15 @@ class Scanner {
$this->scanFile($parent); $this->scanFile($parent);
} }
} }
$id = $this->cache->put($file, $data); if ($checkExisting and $cacheData = $this->cache->get($file)) {
if ($data['size'] === -1) {
$data['size'] = $cacheData['size'];
}
if ($data['mtime'] === $cacheData['mtime']) {
$data['etag'] = $cacheData['etag'];
}
}
$this->cache->put($file, $data);
} }
return $data; return $data;
} }
...@@ -99,20 +108,18 @@ class Scanner { ...@@ -99,20 +108,18 @@ class Scanner {
while ($file = readdir($dh)) { while ($file = readdir($dh)) {
if (!$this->isIgnoredFile($file)) { if (!$this->isIgnoredFile($file)) {
$child = ($path) ? $path . '/' . $file : $file; $child = ($path) ? $path . '/' . $file : $file;
$data = $this->scanFile($child); $data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) { if ($data) {
if ($data['mimetype'] === 'httpd/unix-directory') { if ($data['size'] === -1) {
if ($recursive === self::SCAN_RECURSIVE) { if ($recursive === self::SCAN_RECURSIVE) {
$childQueue[] = $child; $childQueue[] = $child;
$data['size'] = 0; $data['size'] = 0;
} else { } else {
$data['size'] = -1; $size = -1;
} }
} else {
} }
if ($data['size'] === -1) {
$size = -1; if ($size !== -1) {
} elseif ($size !== -1) {
$size += $data['size']; $size += $data['size'];
} }
} }
...@@ -143,8 +150,8 @@ class Scanner { ...@@ -143,8 +150,8 @@ class Scanner {
*/ */
private function isIgnoredFile($file) { private function isIgnoredFile($file) {
if ($file === '.' || $file === '..' if ($file === '.' || $file === '..'
|| pathinfo($file,PATHINFO_EXTENSION) === 'part') || pathinfo($file, PATHINFO_EXTENSION) === 'part'
{ ) {
return true; return true;
} }
return false; return false;
......
...@@ -76,7 +76,6 @@ class Watcher extends \PHPUnit_Framework_TestCase { ...@@ -76,7 +76,6 @@ class Watcher extends \PHPUnit_Framework_TestCase {
$updater->checkUpdate(''); $updater->checkUpdate('');
$entry = $cache->get('foo.txt'); $entry = $cache->get('foo.txt');
$this->assertEquals(-1, $entry['size']);
$this->assertEquals('httpd/unix-directory', $entry['mimetype']); $this->assertEquals('httpd/unix-directory', $entry['mimetype']);
$this->assertFalse($cache->inCache('folder')); $this->assertFalse($cache->inCache('folder'));
$this->assertFalse($cache->inCache('folder/bar.txt')); $this->assertFalse($cache->inCache('folder/bar.txt'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment