diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-08-01 08:05:19 -0700 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-08-01 08:05:19 -0700 |
commit | eed63ae5127680011256093588a7c68ca95ddd02 (patch) | |
tree | 39a5ebefd4dbb0a97f0eb7c5aebda0cc6292bcd5 /lib/files | |
parent | 930f0e4c1824405f2be8144187613271fe169c73 (diff) | |
parent | afff75001156e38620e08f81cad6372abb54ebb1 (diff) | |
download | nextcloud-server-eed63ae5127680011256093588a7c68ca95ddd02.tar.gz nextcloud-server-eed63ae5127680011256093588a7c68ca95ddd02.zip |
Merge pull request #4221 from owncloud/fix-3698
Fix calculating size for empty folders
Diffstat (limited to 'lib/files')
-rw-r--r-- | lib/files/cache/cache.php | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 5b8dc46b771..39e36684b7b 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -485,28 +485,28 @@ class Cache { * @return int */ public function calculateFolderSize($path) { - $id = $this->getId($path); - if ($id === -1) { - return 0; - } - $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?'; - $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); $totalSize = 0; - $hasChilds = 0; - while ($row = $result->fetchRow()) { - $hasChilds = true; - $size = (int)$row['size']; - if ($size === -1) { - $totalSize = -1; - break; - } else { - $totalSize += $size; + $entry = $this->get($path); + if ($entry && $entry['mimetype'] === 'httpd/unix-directory') { + $id = $entry['fileid']; + $sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` '. + 'WHERE `parent` = ? AND `storage` = ?'; + $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)); + } + } } - - if ($hasChilds) { - $this->update($id, array('size' => $totalSize)); - } return $totalSize; } |