summaryrefslogtreecommitdiffstats
path: root/lib/private/files/cache
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/files/cache')
-rw-r--r--lib/private/files/cache/backgroundwatcher.php3
-rw-r--r--lib/private/files/cache/cache.php2
-rw-r--r--lib/private/files/cache/homecache.php3
-rw-r--r--lib/private/files/cache/legacy.php5
-rw-r--r--lib/private/files/cache/storage.php6
-rw-r--r--lib/private/files/cache/updater.php4
-rw-r--r--lib/private/files/cache/watcher.php46
7 files changed, 51 insertions, 18 deletions
diff --git a/lib/private/files/cache/backgroundwatcher.php b/lib/private/files/cache/backgroundwatcher.php
index 923804f48d0..2194651233d 100644
--- a/lib/private/files/cache/backgroundwatcher.php
+++ b/lib/private/files/cache/backgroundwatcher.php
@@ -24,6 +24,9 @@ class BackgroundWatcher {
return $row['id'];
}
+ /**
+ * @param integer $id
+ */
static private function checkUpdate($id) {
$cacheItem = Cache::getById($id);
if (is_null($cacheItem)) {
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 1e7936ca26d..4cab4619149 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -487,7 +487,7 @@ class Cache {
/**
* update the folder size and the size of all parent folders
*
- * @param $path
+ * @param string|boolean $path
*/
public function correctFolderSize($path) {
$this->calculateFolderSize($path);
diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php
index 71bb944da71..a7c310a3782 100644
--- a/lib/private/files/cache/homecache.php
+++ b/lib/private/files/cache/homecache.php
@@ -38,6 +38,9 @@ class HomeCache extends Cache {
return $totalSize;
}
+ /**
+ * @param string $path
+ */
public function get($path) {
$data = parent::get($path);
if ($path === '' or $path === '/') {
diff --git a/lib/private/files/cache/legacy.php b/lib/private/files/cache/legacy.php
index 8eed1f67a5d..4d5f58741e9 100644
--- a/lib/private/files/cache/legacy.php
+++ b/lib/private/files/cache/legacy.php
@@ -16,6 +16,9 @@ class Legacy {
private $cacheHasItems = null;
+ /**
+ * @param string $user
+ */
public function __construct($user) {
$this->user = $user;
}
@@ -69,7 +72,7 @@ class Legacy {
/**
* get an item from the legacy cache
*
- * @param string|int $path
+ * @param string $path
* @return array
*/
function get($path) {
diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php
index 5b1b30176e8..6b6b0bce9d7 100644
--- a/lib/private/files/cache/storage.php
+++ b/lib/private/files/cache/storage.php
@@ -47,6 +47,9 @@ class Storage {
return $this->numericId;
}
+ /**
+ * @return string
+ */
public static function getStorageId($numericId) {
$sql = 'SELECT `id` FROM `*PREFIX*storages` WHERE `numeric_id` = ?';
@@ -58,6 +61,9 @@ class Storage {
}
}
+ /**
+ * @param string $storageId
+ */
public static function exists($storageId) {
if (strlen($storageId) > 64) {
$storageId = md5($storageId);
diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php
index 73bc30e538f..7a45b9e9e96 100644
--- a/lib/private/files/cache/updater.php
+++ b/lib/private/files/cache/updater.php
@@ -8,8 +8,6 @@
namespace OC\Files\Cache;
-use OCP\Util;
-
/**
* listen to filesystem hooks and change the cache accordingly
*/
@@ -112,7 +110,7 @@ class Updater {
/**
* @brief get file owner and path
* @param string $filename
- * @return array with the oweners uid and the owners path
+ * @return string[] with the oweners uid and the owners path
*/
private static function getUidAndFilename($filename) {
diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php
index 251ecbe7071..48aa6f853ce 100644
--- a/lib/private/files/cache/watcher.php
+++ b/lib/private/files/cache/watcher.php
@@ -12,6 +12,14 @@ namespace OC\Files\Cache;
* check the storage backends for updates and change the cache accordingly
*/
class Watcher {
+ const CHECK_NEVER = 0; // never check the underlying filesystem for updates
+ const CHECK_ONCE = 1; // check the underlying filesystem for updates once every request for each file
+ const CHECK_ALWAYS = 2; // always check the underlying filesystem for updates
+
+ protected $watchPolicy = self::CHECK_ONCE;
+
+ protected $checkedPaths = array();
+
/**
* @var \OC\Files\Storage\Storage $storage
*/
@@ -23,7 +31,7 @@ class Watcher {
protected $cache;
/**
- * @var Scanner $scanner;
+ * @var Scanner $scanner ;
*/
protected $scanner;
@@ -37,26 +45,38 @@ class Watcher {
}
/**
+ * @param int $policy either \OC\Files\Cache\Watcher::UPDATE_NEVER, \OC\Files\Cache\Watcher::UPDATE_ONCE, \OC\Files\Cache\Watcher::UPDATE_ALWAYS
+ */
+ public function setPolicy($policy) {
+ $this->watchPolicy = $policy;
+ }
+
+ /**
* check $path for updates
*
* @param string $path
* @return boolean | array true if path was updated, otherwise the cached data is returned
*/
public function checkUpdate($path) {
- $cachedEntry = $this->cache->get($path);
- if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) {
- if ($this->storage->is_dir($path)) {
- $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
- } else {
- $this->scanner->scanFile($path);
- }
- if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
- $this->cleanFolder($path);
+ if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false)) {
+ $cachedEntry = $this->cache->get($path);
+ $this->checkedPaths[] = $path;
+ if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) {
+ if ($this->storage->is_dir($path)) {
+ $this->scanner->scan($path, Scanner::SCAN_SHALLOW);
+ } else {
+ $this->scanner->scanFile($path);
+ }
+ if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
+ $this->cleanFolder($path);
+ }
+ $this->cache->correctFolderSize($path);
+ return true;
}
- $this->cache->correctFolderSize($path);
- return true;
+ return $cachedEntry;
+ } else {
+ return false;
}
- return $cachedEntry;
}
/**