Merge pull request #4221 from owncloud/fix-3698
Fix calculating size for empty folders
This commit is contained in:
commit
eed63ae512
|
@ -485,27 +485,27 @@ class Cache {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function calculateFolderSize($path) {
|
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;
|
$totalSize = 0;
|
||||||
$hasChilds = 0;
|
$entry = $this->get($path);
|
||||||
while ($row = $result->fetchRow()) {
|
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
|
||||||
$hasChilds = true;
|
$id = $entry['fileid'];
|
||||||
$size = (int)$row['size'];
|
$sql = 'SELECT SUM(`size`), MIN(`size`) FROM `*PREFIX*filecache` '.
|
||||||
if ($size === -1) {
|
'WHERE `parent` = ? AND `storage` = ?';
|
||||||
$totalSize = -1;
|
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
|
||||||
break;
|
if ($row = $result->fetchRow()) {
|
||||||
} else {
|
list($sum, $min) = array_values($row);
|
||||||
$totalSize += $size;
|
$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;
|
return $totalSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,11 @@ class Cache extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
$this->assertEquals(1025, $this->cache->calculateFolderSize($file1));
|
$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->cache->remove('folder');
|
||||||
$this->assertFalse($this->cache->inCache('folder/foo'));
|
$this->assertFalse($this->cache->inCache('folder/foo'));
|
||||||
$this->assertFalse($this->cache->inCache('folder/bar'));
|
$this->assertFalse($this->cache->inCache('folder/bar'));
|
||||||
|
|
Loading…
Reference in New Issue