You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HomeCache.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Andreas Fischer <bantu@owncloud.com>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Vincent Petry <vincent@nextcloud.com>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Files\Cache;
  30. use OCP\Files\Cache\ICacheEntry;
  31. class HomeCache extends Cache {
  32. /**
  33. * get the size of a folder and set it in the cache
  34. *
  35. * @param string $path
  36. * @param array|null|ICacheEntry $entry (optional) meta data of the folder
  37. * @return int|float
  38. */
  39. public function calculateFolderSize($path, $entry = null) {
  40. if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
  41. return parent::calculateFolderSize($path, $entry);
  42. } elseif ($path === '' or $path === '/') {
  43. // since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
  44. return 0;
  45. } else {
  46. return $this->calculateFolderSizeInner($path, $entry, true);
  47. }
  48. }
  49. /**
  50. * @param string $file
  51. * @return ICacheEntry
  52. */
  53. public function get($file) {
  54. $data = parent::get($file);
  55. if ($file === '' or $file === '/') {
  56. // only the size of the "files" dir counts
  57. $filesData = parent::get('files');
  58. if (isset($filesData['size'])) {
  59. $data['size'] = $filesData['size'];
  60. }
  61. }
  62. return $data;
  63. }
  64. }