summaryrefslogtreecommitdiffstats
path: root/lib/private/files
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-11-08 12:57:28 +0100
committerVincent Petry <pvince81@owncloud.com>2013-11-12 16:15:43 +0100
commit32a703ab3643842d3262fcc8c6ac014c3e54d8ea (patch)
tree308797a77a829d12c67852b90a2c0bfc5358bc4a /lib/private/files
parenta745901d50c67728c0a8b7f0a8820ebd6992bad6 (diff)
downloadnextcloud-server-32a703ab3643842d3262fcc8c6ac014c3e54d8ea.tar.gz
nextcloud-server-32a703ab3643842d3262fcc8c6ac014c3e54d8ea.zip
Do not use -1 as the size for the root folder of the home storage
Diffstat (limited to 'lib/private/files')
-rw-r--r--lib/private/files/cache/homecache.php48
-rw-r--r--lib/private/files/storage/common.php10
-rw-r--r--lib/private/files/storage/home.php7
3 files changed, 60 insertions, 5 deletions
diff --git a/lib/private/files/cache/homecache.php b/lib/private/files/cache/homecache.php
new file mode 100644
index 00000000000..4439896e6e7
--- /dev/null
+++ b/lib/private/files/cache/homecache.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Cache;
+
+class HomeCache extends Cache {
+ /**
+ * get the size of a folder and set it in the cache
+ *
+ * @param string $path
+ * @return int
+ */
+ public function calculateFolderSize($path) {
+ $totalSize = 0;
+ $entry = $this->get($path);
+ if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
+ $isRoot = ($path === '/' or $path === '');
+ $id = $entry['fileid'];
+ $sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` ' .
+ 'WHERE `parent` = ? AND `storage` = ?';
+ if ($isRoot) {
+ // filter out non-scanned dirs at the root
+ $sql .= ' AND `size` >= 0';
+ }
+ $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
+ if ($row = $result->fetchRow()) {
+ list($sum, $min) = array_values($row);
+ $sum = (int)$sum;
+ $min = (int)$min;
+ if ($min === -1) {
+ $totalSize = $min;
+ } else {
+ $totalSize = $sum;
+ }
+ if ($entry['size'] !== $totalSize) {
+ $this->update($id, array('size' => $totalSize));
+ }
+
+ }
+ }
+ return $totalSize;
+ }
+}
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index a5b79f0e967..3943d667c35 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -21,11 +21,11 @@ namespace OC\Files\Storage;
*/
abstract class Common implements \OC\Files\Storage\Storage {
- private $cache;
- private $scanner;
- private $permissioncache;
- private $watcher;
- private $storageCache;
+ protected $cache;
+ protected $scanner;
+ protected $permissioncache;
+ protected $watcher;
+ protected $storageCache;
public function __construct($parameters) {
}
diff --git a/lib/private/files/storage/home.php b/lib/private/files/storage/home.php
index bf1d6017cbf..22753519ad3 100644
--- a/lib/private/files/storage/home.php
+++ b/lib/private/files/storage/home.php
@@ -27,4 +27,11 @@ class Home extends Local {
public function getId() {
return 'home::' . $this->user->getUID();
}
+
+ public function getCache($path = '') {
+ if (!isset($this->cache)) {
+ $this->cache = new \OC\Files\Cache\HomeCache($this);
+ }
+ return $this->cache;
+ }
}