1
0

Scanner.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-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\External;
  8. use OC\ForbiddenException;
  9. use OCP\Files\NotFoundException;
  10. use OCP\Files\StorageInvalidException;
  11. use OCP\Files\StorageNotAvailableException;
  12. class Scanner extends \OC\Files\Cache\Scanner {
  13. /** @var Storage */
  14. protected $storage;
  15. public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
  16. // Disable locking for federated shares
  17. parent::scan($path, $recursive, $reuse, false);
  18. }
  19. /**
  20. * Scan a single file and store it in the cache.
  21. * If an exception happened while accessing the external storage,
  22. * the storage will be checked for availability and removed
  23. * if it is not available any more.
  24. *
  25. * @param string $file file to scan
  26. * @param int $reuseExisting
  27. * @param int $parentId
  28. * @param array | null $cacheData existing data in the cache for the file to be scanned
  29. * @param bool $lock set to false to disable getting an additional read lock during scanning
  30. * @return array | null an array of metadata of the scanned file
  31. */
  32. public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true, $data = null) {
  33. try {
  34. return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock, $data);
  35. } catch (ForbiddenException $e) {
  36. $this->storage->checkStorageAvailability();
  37. } catch (NotFoundException $e) {
  38. // if the storage isn't found, the call to
  39. // checkStorageAvailable() will verify it and remove it
  40. // if appropriate
  41. $this->storage->checkStorageAvailability();
  42. } catch (StorageInvalidException $e) {
  43. $this->storage->checkStorageAvailability();
  44. } catch (StorageNotAvailableException $e) {
  45. $this->storage->checkStorageAvailability();
  46. }
  47. }
  48. }