From 02cdd52fb0f4e6544f6f0df2a9d4da3c944e3109 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 19 Jul 2013 16:32:43 +0200 Subject: Make Cache\Scanner an emitter --- lib/files/cache/scanner.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index 9b94a24f481..bcd6032fcac 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -9,8 +9,18 @@ namespace OC\Files\Cache; use OC\Files\Filesystem; +use OC\Hooks\BasicEmitter; -class Scanner { +/** + * Class Scanner + * + * Hooks available in scope \OC\Files\Cache\Scanner: + * - scanFile(string $path, string $storageId) + * - scanFolder(string $path, string $storageId) + * + * @package OC\Files\Cache + */ +class Scanner extends BasicEmitter { /** * @var \OC\Files\Storage\Storage $storage */ @@ -71,6 +81,7 @@ class Scanner { if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file) ) { + $this->emit('\OC\Files\Cache\Scanner', 'scanFile', array($file, $this->storageId)); \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId)); $data = $this->getData($file); if ($data) { @@ -134,7 +145,7 @@ class Scanner { if ($reuse === -1) { $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0; } - \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_folder', array('path' => $path, 'storage' => $this->storageId)); + $this->emit('\OC\Files\Cache\Scanner', 'scanFolder', array($path, $this->storageId)); $size = 0; $childQueue = array(); $existingChildren = array(); -- cgit v1.2.3 From e1e7b6a9406d8f9512f37e44d396be12dc1d02df Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 27 Jul 2013 11:36:27 +0200 Subject: Cache: don't check if the parent exists in the cache if we are already sure it does --- lib/files/cache/scanner.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index bcd6032fcac..d8e58f624a1 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -75,9 +75,10 @@ class Scanner extends BasicEmitter { * * @param string $file * @param int $reuseExisting + * @param bool $parentExists * @return array with metadata of the scanned file */ - public function scanFile($file, $reuseExisting = 0) { + public function scanFile($file, $reuseExisting = 0, $parentExists = false) { if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file) ) { @@ -85,7 +86,7 @@ class Scanner extends BasicEmitter { \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId)); $data = $this->getData($file); if ($data) { - if ($file) { + if ($file and !$parentExists) { $parent = dirname($file); if ($parent === '.' or $parent === '/') { $parent = ''; @@ -162,7 +163,7 @@ class Scanner extends BasicEmitter { $child = ($path) ? $path . '/' . $file : $file; if (!Filesystem::isIgnoredDir($file)) { $newChildren[] = $file; - $data = $this->scanFile($child, $reuse); + $data = $this->scanFile($child, $reuse, true); if ($data) { if ($data['size'] === -1) { if ($recursive === self::SCAN_RECURSIVE) { -- cgit v1.2.3 From c8e60900fc75de39fbdf4dc6880f2e1cd61654ec Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Sun, 28 Jul 2013 15:32:48 -0400 Subject: Move check so the variable will never be undefined --- lib/files/cache/scanner.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index bcd6032fcac..520b41fe104 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -108,9 +108,9 @@ class Scanner extends BasicEmitter { // Only update metadata that has changed $newData = array_diff($data, $cacheData); } - } - if (!empty($newData)) { - $this->cache->put($file, $newData); + if (!empty($newData)) { + $this->cache->put($file, $newData); + } } return $data; } -- cgit v1.2.3 From 74c54587ec1d816b41e5fbfca6f8d61f334a280c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 29 Jul 2013 18:27:19 +0200 Subject: better variable naming --- lib/files/cache/scanner.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/files/cache') diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php index d8e58f624a1..53dc45e047c 100644 --- a/lib/files/cache/scanner.php +++ b/lib/files/cache/scanner.php @@ -75,10 +75,10 @@ class Scanner extends BasicEmitter { * * @param string $file * @param int $reuseExisting - * @param bool $parentExists + * @param bool $parentExistsInCache * @return array with metadata of the scanned file */ - public function scanFile($file, $reuseExisting = 0, $parentExists = false) { + public function scanFile($file, $reuseExisting = 0, $parentExistsInCache = false) { if (!self::isPartialFile($file) and !Filesystem::isFileBlacklisted($file) ) { @@ -86,7 +86,7 @@ class Scanner extends BasicEmitter { \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId)); $data = $this->getData($file); if ($data) { - if ($file and !$parentExists) { + if ($file and !$parentExistsInCache) { $parent = dirname($file); if ($parent === '.' or $parent === '/') { $parent = ''; -- cgit v1.2.3