Fix calculating size for empty folders
This commit is contained in:
parent
48621115c1
commit
dd4e33fe6b
1 changed files with 16 additions and 19 deletions
35
lib/files/cache/cache.php
vendored
35
lib/files/cache/cache.php
vendored
|
@ -485,27 +485,24 @@ 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 `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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue