Scanner.php 1.7 KB

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