Fix calculating size for empty folders

This commit is contained in:
Michael Gapczynski 2013-07-28 16:14:49 -04:00
parent 48621115c1
commit dd4e33fe6b

View file

@ -485,16 +485,13 @@ class Cache {
* @return int
*/
public function calculateFolderSize($path) {
$id = $this->getId($path);
if ($id === -1) {
return 0;
}
$totalSize = 0;
$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()));
$totalSize = 0;
$hasChilds = 0;
while ($row = $result->fetchRow()) {
$hasChilds = true;
$size = (int)$row['size'];
if ($size === -1) {
$totalSize = -1;
@ -503,10 +500,10 @@ class Cache {
$totalSize += $size;
}
}
if ($hasChilds) {
if ($entry['size'] !== $totalSize) {
$this->update($id, array('size' => $totalSize));
}
}
return $totalSize;
}