aboutsummaryrefslogtreecommitdiffstats
path: root/lib/files/cache/scanner.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-05-21 23:35:19 +0200
committerRobin Appelman <icewind@owncloud.com>2013-05-21 23:35:19 +0200
commit81fd1badc3feb72c3a4e597c670e8adcdca525da (patch)
treedda3deee50551ebdffa8a9021b528ac29fdbf369 /lib/files/cache/scanner.php
parentd7beac6d6f3ad588cee6c5ba8a2145b42fa184a2 (diff)
parentfb4d8ddf0a76da7e9f806b837f9cf23699671f75 (diff)
downloadnextcloud-server-81fd1badc3feb72c3a4e597c670e8adcdca525da.tar.gz
nextcloud-server-81fd1badc3feb72c3a4e597c670e8adcdca525da.zip
merge master into filecache_mtime
Diffstat (limited to 'lib/files/cache/scanner.php')
-rw-r--r--lib/files/cache/scanner.php72
1 files changed, 46 insertions, 26 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index 9c5ce9df7fc..a98953b42aa 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -63,36 +63,44 @@ class Scanner {
* @return array with metadata of the scanned 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) {
- if ($file) {
- $parent = dirname($file);
- if ($parent === '.') {
- $parent = '';
- }
- if (!$this->cache->inCache($parent)) {
- $this->scanFile($parent);
+ if ( ! self::isPartialFile($file)
+ and ! \OC\Files\Filesystem::isFileBlacklisted($file)
+ ) {
+ \OC_Hook::emit('\OC\Files\Cache\Scanner', 'scan_file', array('path' => $file, 'storage' => $this->storageId));
+ $data = $this->getData($file);
+ if ($data) {
+ if ($file) {
+ $parent = dirname($file);
+ if ($parent === '.' or $parent === '/') {
+ $parent = '';
+ }
+ if (!$this->cache->inCache($parent)) {
+ $this->scanFile($parent);
+ }
}
- }
- if ($checkExisting and $cacheData = $this->cache->get($file)) {
- if ($data['size'] === -1) {
- $data['size'] = $cacheData['size'];
+ if($cacheData = $this->cache->get($file)) {
+ if ($data['mtime'] === $cacheData['mtime'] &&
+ $data['size'] === $cacheData['size']) {
+ $data['etag'] = $cacheData['etag'];
+ }
}
- if ($data['mtime'] === $cacheData['mtime']) {
- $data['etag'] = $cacheData['etag'];
+ if ($checkExisting and $cacheData) {
+ if ($data['size'] === -1) {
+ $data['size'] = $cacheData['size'];
+ }
}
+ $this->cache->put($file, $data);
}
- $this->cache->put($file, $data);
+ return $data;
}
- return $data;
+ return null;
}
/**
* scan all the files in a folder and store them in the cache
*
* @param string $path
- * @param SCAN_RECURSIVE/SCAN_SHALLOW $recursive
+ * @param bool $recursive
* @param bool $onlyChilds
* @return int the size of the scanned folder or -1 if the size is unknown at this stage
*/
@@ -107,8 +115,8 @@ class Scanner {
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
- if (!$this->isIgnoredFile($file)) {
- $child = ($path) ? $path . '/' . $file : $file;
+ $child = ($path) ? $path . '/' . $file : $file;
+ if (!$this->isIgnoredDir($file)) {
$data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) {
if ($data['size'] === -1) {
@@ -143,16 +151,26 @@ class Scanner {
}
/**
+ * @brief check if the directory should be ignored when scanning
+ * NOTE: the special directories . and .. would cause never ending recursion
+ * @param String $dir
+ * @return boolean
+ */
+ private function isIgnoredDir($dir) {
+ if ($dir === '.' || $dir === '..') {
+ return true;
+ }
+ return false;
+ }
+ /**
* @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'
- ) {
+ public static function isPartialFile($file) {
+ if (pathinfo($file, PATHINFO_EXTENSION) === 'part') {
return true;
}
return false;
@@ -162,9 +180,11 @@ class Scanner {
* walk over any folders that are not fully scanned yet and scan them
*/
public function backgroundScan() {
- while (($path = $this->cache->getIncomplete()) !== false) {
+ $lastPath = null;
+ while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
$this->scan($path);
$this->cache->correctFolderSize($path);
+ $lastPath = $path;
}
}
}