From: Michael Gapczynski Date: Sun, 28 Jul 2013 20:14:49 +0000 (-0400) Subject: Fix calculating size for empty folders X-Git-Tag: v5.0.10~22 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=502a479eb64f1fba3bdab9d59bb1581b0d56d05e;p=nextcloud-server.git Fix calculating size for empty folders Conflicts: lib/files/cache/cache.php --- diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 7b38f1290dd..f605d72a6b3 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -499,27 +499,24 @@ class Cache { * @return int */ public function calculateFolderSize($path) { - $id = $this->getId($path); - if ($id === -1) { - return 0; - } - $query = \OC_DB::prepare('SELECT `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?'); - $result = $query->execute(array($id, $this->numericId)); $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 `size` FROM `*PREFIX*filecache` WHERE `parent` = ? AND `storage` = ?'; + $result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId())); + while ($row = $result->fetchRow()) { + $size = (int)$row['size']; + if ($size === -1) { + $totalSize = -1; + break; + } else { + $totalSize += $size; + } + } + if ($entry['size'] !== $totalSize) { + $this->update($id, array('size' => $totalSize)); } - } - - if ($hasChilds) { - $this->update($id, array('size' => $totalSize)); } return $totalSize; }