2013-11-08 15:57:28 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-02-26 13:37:37 +03:00
|
|
|
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
2013-11-08 15:57:28 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2013-11-08 15:57:28 +04:00
|
|
|
namespace OC\Files\Cache;
|
|
|
|
|
|
|
|
class HomeCache extends Cache {
|
|
|
|
/**
|
|
|
|
* get the size of a folder and set it in the cache
|
|
|
|
*
|
|
|
|
* @param string $path
|
2014-02-28 17:23:07 +04:00
|
|
|
* @param array $entry (optional) meta data of the folder
|
2013-11-08 15:57:28 +04:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-02-28 17:23:07 +04:00
|
|
|
public function calculateFolderSize($path, $entry = null) {
|
2014-05-06 15:55:26 +04:00
|
|
|
if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
|
2014-02-28 17:23:07 +04:00
|
|
|
return parent::calculateFolderSize($path, $entry);
|
|
|
|
} elseif ($path === '' or $path === '/') {
|
|
|
|
// since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
|
|
|
|
return 0;
|
2013-11-12 17:17:55 +04:00
|
|
|
}
|
|
|
|
|
2013-11-08 15:57:28 +04:00
|
|
|
$totalSize = 0;
|
2014-02-28 17:23:07 +04:00
|
|
|
if (is_null($entry)) {
|
|
|
|
$entry = $this->get($path);
|
|
|
|
}
|
2013-11-08 15:57:28 +04:00
|
|
|
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
|
|
|
|
$id = $entry['fileid'];
|
2014-03-07 14:00:22 +04:00
|
|
|
$sql = 'SELECT SUM(`size`) AS f1, ' .
|
|
|
|
'SUM(`unencrypted_size`) AS f2 FROM `*PREFIX*filecache` ' .
|
2013-11-12 17:17:55 +04:00
|
|
|
'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
|
2013-11-08 15:57:28 +04:00
|
|
|
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
|
|
|
|
if ($row = $result->fetchRow()) {
|
2014-11-28 11:35:31 +03:00
|
|
|
$result->closeCursor();
|
2014-03-07 14:00:22 +04:00
|
|
|
list($sum, $unencryptedSum) = array_values($row);
|
2014-02-16 04:03:39 +04:00
|
|
|
$totalSize = 0 + $sum;
|
|
|
|
$unencryptedSize = 0 + $unencryptedSum;
|
|
|
|
$entry['size'] += 0;
|
2014-08-05 17:12:00 +04:00
|
|
|
if (!isset($entry['unencrypted_size'])) {
|
|
|
|
$entry['unencrypted_size'] = 0;
|
|
|
|
}
|
2014-02-16 04:03:39 +04:00
|
|
|
$entry['unencrypted_size'] += 0;
|
2013-11-08 15:57:28 +04:00
|
|
|
if ($entry['size'] !== $totalSize) {
|
|
|
|
$this->update($id, array('size' => $totalSize));
|
|
|
|
}
|
2014-03-07 14:00:22 +04:00
|
|
|
if ($entry['unencrypted_size'] !== $unencryptedSize) {
|
|
|
|
$this->update($id, array('unencrypted_size' => $unencryptedSize));
|
|
|
|
}
|
2013-11-08 15:57:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $totalSize;
|
|
|
|
}
|
2013-11-18 20:39:52 +04:00
|
|
|
|
2014-02-06 19:30:58 +04:00
|
|
|
/**
|
|
|
|
* @param string $path
|
2014-02-28 17:23:07 +04:00
|
|
|
* @return array
|
2014-02-06 19:30:58 +04:00
|
|
|
*/
|
2013-11-18 20:39:52 +04:00
|
|
|
public function get($path) {
|
|
|
|
$data = parent::get($path);
|
|
|
|
if ($path === '' or $path === '/') {
|
|
|
|
// only the size of the "files" dir counts
|
|
|
|
$filesData = parent::get('files');
|
|
|
|
|
|
|
|
if (isset($filesData['size'])) {
|
|
|
|
$data['size'] = $filesData['size'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2013-11-08 15:57:28 +04:00
|
|
|
}
|