Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörn Friedrich Dreyer <jfd@butonic.de>2013-03-22 16:52:07 +0400
committerJörn Friedrich Dreyer <jfd@butonic.de>2013-03-28 15:21:00 +0400
commit2bb22d3aab9f959dd41ae67435492bbfa22a01d7 (patch)
treec7739b500f92bd8cb2a818b0703dd9216bbb4b51
parent4742d0eb9458bdcb20a948a23a38f82d0f4d07ee (diff)
ignore files in scanFile instead of scan to catch all occurences.
Conflicts: lib/files/cache/scanner.php
-rw-r--r--lib/files/cache/scanner.php68
1 files changed, 43 insertions, 25 deletions
diff --git a/lib/files/cache/scanner.php b/lib/files/cache/scanner.php
index e1f5cb1f377..2052182efae 100644
--- a/lib/files/cache/scanner.php
+++ b/lib/files/cache/scanner.php
@@ -62,39 +62,43 @@ 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 (!$this->isIgnoredFile($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 === '.') {
+ $parent = '';
+ }
+ if (!$this->cache->inCache($parent)) {
+ $this->scanFile($parent);
+ }
}
- }
- if($cacheData = $this->cache->get($file)) {
- if ($data['mtime'] === $cacheData['mtime'] &&
- $data['size'] === $cacheData['size']) {
- $data['etag'] = $cacheData['etag'];
+ if($cacheData = $this->cache->get($file)) {
+ if ($data['mtime'] === $cacheData['mtime'] &&
+ $data['size'] === $cacheData['size']) {
+ $data['etag'] = $cacheData['etag'];
+ }
}
- }
- if ($checkExisting and $cacheData) {
- if ($data['size'] === -1) {
- $data['size'] = $cacheData['size'];
+ 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;
+ \OCP\Util::writeLog('scanner', 'Ignoring '.$file.' and not triggering scan_file hook.', \OCP\Util::DEBUG);
+ 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
*/
@@ -109,7 +113,7 @@ class Scanner {
if ($this->storage->is_dir($path) && ($dh = $this->storage->opendir($path))) {
\OC_DB::beginTransaction();
while ($file = readdir($dh)) {
- if (!$this->isIgnoredFile($file)) {
+ if (!$this->isIgnoredDir($file)) {
$child = ($path) ? $path . '/' . $file : $file;
$data = $this->scanFile($child, $recursive === self::SCAN_SHALLOW);
if ($data) {
@@ -145,6 +149,20 @@ 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 === '..'
+ || \OC\Files\Filesystem::isFileBlacklisted($file)
+ ) {
+ 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
@@ -152,8 +170,8 @@ class Scanner {
* @return boolean
*/
private function isIgnoredFile($file) {
- if ($file === '.' || $file === '..'
- || pathinfo($file, PATHINFO_EXTENSION) === 'part'
+ if (pathinfo($file, PATHINFO_EXTENSION) === 'part'
+ || \OC\Files\Filesystem::isFileBlacklisted($file)
) {
return true;
}