Scanner.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <pvince81@owncloud.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. list($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) {
  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. }