2013-11-08 15:57:28 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Andreas Fischer <bantu@owncloud.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
2016-01-12 17:02:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
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;
|
|
|
|
|
2015-12-02 16:59:13 +03:00
|
|
|
use OCP\Files\Cache\ICacheEntry;
|
|
|
|
|
2013-11-08 15:57:28 +04:00
|
|
|
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'];
|
2015-03-30 18:29:05 +03:00
|
|
|
$sql = 'SELECT SUM(`size`) AS f1 ' .
|
|
|
|
'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();
|
2015-03-30 18:29:05 +03:00
|
|
|
list($sum) = array_values($row);
|
2014-02-16 04:03:39 +04:00
|
|
|
$totalSize = 0 + $sum;
|
|
|
|
$entry['size'] += 0;
|
2013-11-08 15:57:28 +04:00
|
|
|
if ($entry['size'] !== $totalSize) {
|
|
|
|
$this->update($id, array('size' => $totalSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $totalSize;
|
|
|
|
}
|
2013-11-18 20:39:52 +04:00
|
|
|
|
2014-02-06 19:30:58 +04:00
|
|
|
/**
|
|
|
|
* @param string $path
|
2015-12-02 16:59:13 +03:00
|
|
|
* @return ICacheEntry
|
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
|
|
|
}
|