1
0

HomeCache.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Files\Cache;
  8. use OCP\Files\Cache\ICacheEntry;
  9. class HomeCache extends Cache {
  10. /**
  11. * get the size of a folder and set it in the cache
  12. *
  13. * @param string $path
  14. * @param array|null|ICacheEntry $entry (optional) meta data of the folder
  15. * @return int|float
  16. */
  17. public function calculateFolderSize($path, $entry = null) {
  18. if ($path !== '/' and $path !== '' and $path !== 'files' and $path !== 'files_trashbin' and $path !== 'files_versions') {
  19. return parent::calculateFolderSize($path, $entry);
  20. } elseif ($path === '' or $path === '/') {
  21. // since the size of / isn't used (the size of /files is used instead) there is no use in calculating it
  22. return 0;
  23. } else {
  24. return $this->calculateFolderSizeInner($path, $entry, true);
  25. }
  26. }
  27. /**
  28. * @param string $file
  29. * @return ICacheEntry
  30. */
  31. public function get($file) {
  32. $data = parent::get($file);
  33. if ($file === '' or $file === '/') {
  34. // only the size of the "files" dir counts
  35. $filesData = parent::get('files');
  36. if (isset($filesData['size'])) {
  37. $data['size'] = $filesData['size'];
  38. }
  39. }
  40. return $data;
  41. }
  42. }