2013-11-08 11:57:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Andreas Fischer <bantu@owncloud.com>
|
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @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 14:02:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-03-26 10:44:34 +00: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 11:57:28 +00:00
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2013-11-08 11:57:28 +00:00
|
|
|
namespace OC\Files\Cache;
|
|
|
|
|
2015-12-02 13:59:13 +00:00
|
|
|
use OCP\Files\Cache\ICacheEntry;
|
|
|
|
|
2013-11-08 11:57:28 +00:00
|
|
|
class HomeCache extends Cache {
|
|
|
|
/**
|
|
|
|
* get the size of a folder and set it in the cache
|
|
|
|
*
|
|
|
|
* @param string $path
|
2014-02-28 13:23:07 +00:00
|
|
|
* @param array $entry (optional) meta data of the folder
|
2013-11-08 11:57:28 +00:00
|
|
|
* @return int
|
|
|
|
*/
|
2014-02-28 13:23:07 +00:00
|
|
|
public function calculateFolderSize($path, $entry = null) {
|
2014-05-06 11:55:26 +00:00
|
|
|
if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
|
2014-02-28 13:23:07 +00: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 13:17:55 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 11:57:28 +00:00
|
|
|
$totalSize = 0;
|
2014-02-28 13:23:07 +00:00
|
|
|
if (is_null($entry)) {
|
|
|
|
$entry = $this->get($path);
|
|
|
|
}
|
2013-11-08 11:57:28 +00:00
|
|
|
if ($entry && $entry['mimetype'] === 'httpd/unix-directory') {
|
|
|
|
$id = $entry['fileid'];
|
2015-03-30 15:29:05 +00:00
|
|
|
$sql = 'SELECT SUM(`size`) AS f1 ' .
|
|
|
|
'FROM `*PREFIX*filecache` ' .
|
2013-11-12 13:17:55 +00:00
|
|
|
'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
|
2013-11-08 11:57:28 +00:00
|
|
|
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
|
|
|
|
if ($row = $result->fetchRow()) {
|
2014-11-28 08:35:31 +00:00
|
|
|
$result->closeCursor();
|
2015-03-30 15:29:05 +00:00
|
|
|
list($sum) = array_values($row);
|
2014-02-16 00:03:39 +00:00
|
|
|
$totalSize = 0 + $sum;
|
|
|
|
$entry['size'] += 0;
|
2013-11-08 11:57:28 +00:00
|
|
|
if ($entry['size'] !== $totalSize) {
|
|
|
|
$this->update($id, array('size' => $totalSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $totalSize;
|
|
|
|
}
|
2013-11-18 16:39:52 +00:00
|
|
|
|
2014-02-06 15:30:58 +00:00
|
|
|
/**
|
|
|
|
* @param string $path
|
2015-12-02 13:59:13 +00:00
|
|
|
* @return ICacheEntry
|
2014-02-06 15:30:58 +00:00
|
|
|
*/
|
2013-11-18 16:39:52 +00: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 11:57:28 +00:00
|
|
|
}
|