Scanner.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 OCA\Files_Sharing;
  8. use OC\Files\ObjectStore\ObjectStoreScanner;
  9. use OC\Files\Storage\Storage;
  10. /**
  11. * Scanner for SharedStorage
  12. */
  13. class Scanner extends \OC\Files\Cache\Scanner {
  14. /**
  15. * @var SharedStorage $storage
  16. */
  17. protected $storage;
  18. private $sourceScanner;
  19. /**
  20. * Returns metadata from the shared storage, but
  21. * with permissions from the source storage.
  22. *
  23. * @param string $path path of the file for which to retrieve metadata
  24. *
  25. * @return array|null an array of metadata of the file
  26. */
  27. public function getData($path) {
  28. $data = parent::getData($path);
  29. if ($data === null) {
  30. return null;
  31. }
  32. $internalPath = $this->storage->getUnjailedPath($path);
  33. $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath);
  34. return $data;
  35. }
  36. private function getSourceScanner() {
  37. if ($this->sourceScanner) {
  38. return $this->sourceScanner;
  39. }
  40. if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
  41. /** @var Storage $storage */
  42. [$storage] = $this->storage->resolvePath('');
  43. $this->sourceScanner = $storage->getScanner();
  44. return $this->sourceScanner;
  45. } else {
  46. return null;
  47. }
  48. }
  49. public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
  50. $sourceScanner = $this->getSourceScanner();
  51. if ($sourceScanner instanceof ObjectStoreScanner) {
  52. // ObjectStoreScanner doesn't scan
  53. return [];
  54. } else {
  55. return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock);
  56. }
  57. }
  58. }