1
0

Scanner.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_Sharing;
  26. use OC\Files\ObjectStore\ObjectStoreScanner;
  27. /**
  28. * Scanner for SharedStorage
  29. */
  30. class Scanner extends \OC\Files\Cache\Scanner {
  31. /**
  32. * @var \OCA\Files_Sharing\SharedStorage $storage
  33. */
  34. protected $storage;
  35. private $sourceScanner;
  36. /**
  37. * Returns metadata from the shared storage, but
  38. * with permissions from the source storage.
  39. *
  40. * @param string $path path of the file for which to retrieve metadata
  41. *
  42. * @return array|null an array of metadata of the file
  43. */
  44. public function getData($path) {
  45. $data = parent::getData($path);
  46. if ($data === null) {
  47. return null;
  48. }
  49. $internalPath = $this->storage->getUnjailedPath($path);
  50. $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath);
  51. return $data;
  52. }
  53. private function getSourceScanner() {
  54. if ($this->sourceScanner) {
  55. return $this->sourceScanner;
  56. }
  57. if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
  58. /** @var \OC\Files\Storage\Storage $storage */
  59. [$storage] = $this->storage->resolvePath('');
  60. $this->sourceScanner = $storage->getScanner();
  61. return $this->sourceScanner;
  62. } else {
  63. return null;
  64. }
  65. }
  66. public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
  67. $sourceScanner = $this->getSourceScanner();
  68. if ($sourceScanner instanceof ObjectStoreScanner) {
  69. // ObjectStoreScanner doesn't scan
  70. return [];
  71. } else {
  72. return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock);
  73. }
  74. }
  75. }