[Pkg-owncloud-commits] [owncloud] 32/85: [backport] [stable6] Skip filescan but execute hooks

David Prévot taffit at moszumanska.debian.org
Tue Jun 17 19:12:42 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch 6.0
in repository owncloud.

commit a908e281e77f6e0d45ea6bb53a763c4227e25157
Author: ringmaster <epithet at gmail.com>
Date:   Thu May 15 22:38:46 2014 -0400

    [backport] [stable6] Skip filescan but execute hooks
    
    Backport of #8607
---
 config/config.sample.php            |  3 +++
 lib/private/files/cache/scanner.php | 50 +++++++++++++++++++++++++++++++------
 2 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/config/config.sample.php b/config/config.sample.php
index 0cf8611..6acfb16 100755
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -254,4 +254,7 @@ $CONFIG = array(
 
 /* whether usage of the instance should be restricted to admin users only */
 'singleuser' => false,
+
+/* If true, prevent owncloud from changing the cache due to changes in the filesystem for all storage */
+'filesystem_cache_readonly' => false,
 );
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index 92a4c01..d756b95 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -10,6 +10,7 @@ namespace OC\Files\Cache;
 
 use OC\Files\Filesystem;
 use OC\Hooks\BasicEmitter;
+use OCP\Config;
 
 /**
  * Class Scanner
@@ -43,6 +44,11 @@ class Scanner extends BasicEmitter {
 	 */
 	private $permissionsCache;
 
+	/**
+	 * @var boolean $cacheActive If true, perform cache operations, if false, do not affect cache
+	 */
+	protected $cacheActive;
+
 	const SCAN_RECURSIVE = true;
 	const SCAN_SHALLOW = false;
 
@@ -54,6 +60,7 @@ class Scanner extends BasicEmitter {
 		$this->storageId = $this->storage->getId();
 		$this->cache = $storage->getCache();
 		$this->permissionsCache = $storage->getPermissionsCache();
+		$this->cacheActive = !Config::getSystemValue('filesystem_cache_readonly', false);
 	}
 
 	/**
@@ -136,9 +143,12 @@ class Scanner extends BasicEmitter {
 											$parent = '';
 										}
 										$parentCacheData = $this->cache->get($parent);
-										$this->cache->update($parentCacheData['fileid'], array(
-											'etag' => $this->storage->getETag($parent),
-										));
+										\OC_Hook::emit('Scanner', 'updateCache', array('file' => $file, 'data' => $data));
+										if($this->cacheActive) {
+											$this->cache->update($parentCacheData['fileid'], array(
+												'etag' => $this->storage->getETag($parent),
+											));
+										}
 									}
 								}
 							}
@@ -155,12 +165,18 @@ class Scanner extends BasicEmitter {
 					}
 				}
 				if (!empty($newData)) {
-					$this->cache->put($file, $newData);
+					\OC_Hook::emit('Scanner', 'addToCache', array('file' => $file, 'data' => $newData));
+					if($this->cacheActive) {
+						$data['fileid'] = $this->cache->put($file, $newData);
+					}
 					$this->emit('\OC\Files\Cache\Scanner', 'postScanFile', array($file, $this->storageId));
 					\OC_Hook::emit('\OC\Files\Cache\Scanner', 'post_scan_file', array('path' => $file, 'storage' => $this->storageId));
 				}
 			} else {
-				$this->cache->remove($file);
+				\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $file));
+				if($this->cacheActive) {
+					$this->cache->remove($file);
+				}
 			}
 			return $data;
 		}
@@ -241,7 +257,10 @@ class Scanner extends BasicEmitter {
 			$removedChildren = \array_diff($existingChildren, $newChildren);
 			foreach ($removedChildren as $childName) {
 				$child = ($path) ? $path . '/' . $childName : $childName;
-				$this->cache->remove($child);
+				\OC_Hook::emit('Scanner', 'removeFromCache', array('file' => $child));
+				if($this->cacheActive) {
+					$this->cache->remove($child);
+				}
 			}
 			\OC_DB::commit();
 			if ($exceptionOccurred){
@@ -260,7 +279,11 @@ class Scanner extends BasicEmitter {
 					$size += $childSize;
 				}
 			}
-			$this->cache->put($path, array('size' => $size));
+			$newData = array('size' => $size);
+			\OC_Hook::emit('Scanner', 'addToCache', array('file' => $child, 'data' => $newData));
+			if($this->cacheActive) {
+				$this->cache->put($path, $newData);
+			}
 		}
 		$this->emit('\OC\Files\Cache\Scanner', 'postScanFolder', array($path, $this->storageId));
 		return $size;
@@ -287,8 +310,19 @@ class Scanner extends BasicEmitter {
 		$lastPath = null;
 		while (($path = $this->cache->getIncomplete()) !== false && $path !== $lastPath) {
 			$this->scan($path, self::SCAN_RECURSIVE, self::REUSE_ETAG);
-			$this->cache->correctFolderSize($path);
+			\OC_Hook::emit('Scanner', 'correctFolderSize', array('path' => $path));
+			if($this->cacheActive) {
+				$this->cache->correctFolderSize($path);
+			}
 			$lastPath = $path;
 		}
 	}
+
+	/**
+	 * Set whether the cache is affected by scan operations
+	 * @param boolean $active The active state of the cache
+	 */
+	public function setCacheActive($active) {
+		$this->cacheActive = $active;
+	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list