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.

Scanner.php 2.4KB

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