summaryrefslogtreecommitdiffstats
path: root/lib/files/cache/scanner.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/files/cache/scanner.php')
-rw-r--r--lib/files/cache/scanner.php45
1 files changed, 34 insertions, 11 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 8d504af6163..88f208547f6 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -58,9 +58,10 @@ class Scanner {
* scan a single file and store it in the cache
*
* @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
*/
- 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));
$data = $this->getData($file);
if ($data) {
@@ -73,7 +74,15 @@ class Scanner {
$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;
}
@@ -97,22 +106,20 @@ class Scanner {
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
- if ($file !== '.' and $file !== '..') {
+ if (!$this->isIgnoredFile($file)) {
$child = ($path) ? $path . '/' . $file : $file;
- $data = $this->scanFile($child);
+ $data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) {
- if ($data['mimetype'] === 'httpd/unix-directory') {
+ if ($data['size'] === -1) {
if ($recursive === self::SCAN_RECURSIVE) {
$childQueue[] = $child;
$data['size'] = 0;
} else {
- $data['size'] = -1;
+ $size = -1;
}
- } else {
}
- if ($data['size'] === -1) {
- $size = -1;
- } elseif ($size !== -1) {
+
+ if ($size !== -1) {
$size += $data['size'];
}
}
@@ -135,10 +142,26 @@ class Scanner {
}
/**
+ * @brief check if the file should be ignored when scanning
+ * NOTE: files with a '.part' extension are ignored as well!
+ * prevents unfinished put requests to be scanned
+ * @param String $file
+ * @return boolean
+ */
+ private function isIgnoredFile($file) {
+ if ($file === '.' || $file === '..'
+ || pathinfo($file, PATHINFO_EXTENSION) === 'part'
+ ) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* walk over any folders that are not fully scanned yet and scan them
*/
public function backgroundScan() {
- while ($path = $this->cache->getIncomplete()) {
+ while (($path = $this->cache->getIncomplete()) !== false) {
$this->scan($path);
$this->cache->correctFolderSize($path);
}