Merge pull request #4221 from owncloud/fix-3698

Fix calculating size for empty folders
This commit is contained in:
Jörn Friedrich Dreyer 2013-08-01 08:05:19 -07:00
commit eed63ae512
2 changed files with 24 additions and 19 deletions

View File

@ -485,27 +485,27 @@ 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;
}

View File

@ -127,6 +127,11 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(1025, $this->cache->calculateFolderSize($file1));
$this->cache->remove($file2);
$this->cache->remove($file3);
$this->cache->remove($file4);
$this->assertEquals(0, $this->cache->calculateFolderSize($file1));
$this->cache->remove('folder');
$this->assertFalse($this->cache->inCache('folder/foo'));
$this->assertFalse($this->cache->inCache('folder/bar'));