diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 45ae555d90ed..2a9bfd2e81dc 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -143,6 +143,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = $etag = $cacheData['etag']; } $fileId = $cacheData['fileid']; + $data['fileid'] = $fileId; // only reuse data if the file hasn't explicitly changed if (isset($data['storage_mtime']) && isset($cacheData['storage_mtime']) && $data['storage_mtime'] === $cacheData['storage_mtime']) { $data['mtime'] = $cacheData['mtime']; @@ -249,9 +250,10 @@ public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) { * @param string $path * @param bool $recursive * @param int $reuse + * @param array $folderData * @return int the size of the scanned folder or -1 if the size is unknown at this stage */ - public function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) { + public function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $folderData = null) { if ($reuse === -1) { $reuse = ($recursive === self::SCAN_SHALLOW) ? self::REUSE_ETAG | self::REUSE_SIZE : 0; } @@ -259,11 +261,14 @@ public function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = $size = 0; $childQueue = array(); $existingChildren = array(); - if ($folderId = $this->cache->getId($path)) { - $children = $this->cache->getFolderContentsById($folderId); - foreach ($children as $child) { - $existingChildren[$child['name']] = $child; - } + if (is_array($folderData) and isset($folderData['fileid'])) { + $folderId = $folderData['fileid']; + } else { + $folderId = $this->cache->getId($path); + } + $children = $this->cache->getFolderContentsById($folderId); + foreach ($children as $child) { + $existingChildren[$child['name']] = $child; } $newChildren = array(); if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) { @@ -281,7 +286,7 @@ public function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = $data = $this->scanFile($child, $reuse, $folderId, $existingData); if ($data) { if ($data['mimetype'] === 'httpd/unix-directory' and $recursive === self::SCAN_RECURSIVE) { - $childQueue[] = $child; + $childQueue[$child] = $data; } else if ($data['size'] === -1) { $size = -1; } else if ($size !== -1) { @@ -314,15 +319,17 @@ public function scanChildren($path, $recursive = self::SCAN_RECURSIVE, $reuse = $this->cache->loadMimetypes(); } - foreach ($childQueue as $child) { - $childSize = $this->scanChildren($child, self::SCAN_RECURSIVE, $reuse); + foreach ($childQueue as $child => $childData) { + $childSize = $this->scanChildren($child, self::SCAN_RECURSIVE, $reuse, $childData); if ($childSize === -1) { $size = -1; } else if ($size !== -1) { $size += $childSize; } } - $this->updateCache($path, array('size' => $size), $folderId); + if (!is_array($folderData) or !isset($folderData['size']) or $folderData['size'] !== $size) { + $this->updateCache($path, array('size' => $size), $folderId); + } } $this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', array($path, $this->storageId)); return $size;