1
0

Scanner.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Olivier Paroz <github@oparoz.com>
  8. * @author Robin Appelman <robin@icewind.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\External;
  27. use OC\ForbiddenException;
  28. use OCP\Files\NotFoundException;
  29. use OCP\Files\StorageInvalidException;
  30. use OCP\Files\StorageNotAvailableException;
  31. class Scanner extends \OC\Files\Cache\Scanner {
  32. /** @var \OCA\Files_Sharing\External\Storage */
  33. protected $storage;
  34. public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
  35. // Disable locking for federated shares
  36. parent::scan($path, $recursive, $reuse, false);
  37. }
  38. /**
  39. * Scan a single file and store it in the cache.
  40. * If an exception happened while accessing the external storage,
  41. * the storage will be checked for availability and removed
  42. * if it is not available any more.
  43. *
  44. * @param string $file file to scan
  45. * @param int $reuseExisting
  46. * @param int $parentId
  47. * @param array | null $cacheData existing data in the cache for the file to be scanned
  48. * @param bool $lock set to false to disable getting an additional read lock during scanning
  49. * @return array | null an array of metadata of the scanned file
  50. */
  51. public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
  52. try {
  53. return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock, $data);
  54. } catch (ForbiddenException $e) {
  55. $this->storage->checkStorageAvailability();
  56. } catch (NotFoundException $e) {
  57. // if the storage isn't found, the call to
  58. // checkStorageAvailable() will verify it and remove it
  59. // if appropriate
  60. $this->storage->checkStorageAvailability();
  61. } catch (StorageInvalidException $e) {
  62. $this->storage->checkStorageAvailability();
  63. } catch (StorageNotAvailableException $e) {
  64. $this->storage->checkStorageAvailability();
  65. }
  66. }
  67. }