FailedStorage.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Files\Storage;
  8. use OC\Files\Cache\FailedCache;
  9. use OCP\Files\Storage\IStorage;
  10. use OCP\Files\StorageNotAvailableException;
  11. use OCP\Lock\ILockingProvider;
  12. /**
  13. * Storage placeholder to represent a missing precondition, storage unavailable
  14. */
  15. class FailedStorage extends Common {
  16. /** @var \Exception */
  17. protected $e;
  18. /**
  19. * @param array $parameters ['exception' => \Exception]
  20. */
  21. public function __construct(array $parameters) {
  22. $this->e = $parameters['exception'];
  23. if (!$this->e) {
  24. throw new \InvalidArgumentException('Missing "exception" argument in FailedStorage constructor');
  25. }
  26. }
  27. public function getId(): string {
  28. // we can't return anything sane here
  29. return 'failedstorage';
  30. }
  31. public function mkdir(string $path): never {
  32. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  33. }
  34. public function rmdir(string $path): never {
  35. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  36. }
  37. public function opendir(string $path): never {
  38. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  39. }
  40. public function is_dir(string $path): never {
  41. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  42. }
  43. public function is_file(string $path): never {
  44. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  45. }
  46. public function stat(string $path): never {
  47. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  48. }
  49. public function filetype(string $path): never {
  50. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  51. }
  52. public function filesize(string $path): never {
  53. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  54. }
  55. public function isCreatable(string $path): never {
  56. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  57. }
  58. public function isReadable(string $path): never {
  59. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  60. }
  61. public function isUpdatable(string $path): never {
  62. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  63. }
  64. public function isDeletable(string $path): never {
  65. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  66. }
  67. public function isSharable(string $path): never {
  68. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  69. }
  70. public function getPermissions(string $path): never {
  71. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  72. }
  73. public function file_exists(string $path): never {
  74. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  75. }
  76. public function filemtime(string $path): never {
  77. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  78. }
  79. public function file_get_contents(string $path): never {
  80. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  81. }
  82. public function file_put_contents(string $path, mixed $data): never {
  83. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  84. }
  85. public function unlink(string $path): never {
  86. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  87. }
  88. public function rename(string $source, string $target): never {
  89. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  90. }
  91. public function copy(string $source, string $target): never {
  92. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  93. }
  94. public function fopen(string $path, string $mode): never {
  95. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  96. }
  97. public function getMimeType(string $path): never {
  98. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  99. }
  100. public function hash(string $type, string $path, bool $raw = false): never {
  101. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  102. }
  103. public function free_space(string $path): never {
  104. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  105. }
  106. public function touch(string $path, ?int $mtime = null): never {
  107. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  108. }
  109. public function getLocalFile(string $path): never {
  110. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  111. }
  112. public function hasUpdated(string $path, int $time): never {
  113. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  114. }
  115. public function getETag(string $path): never {
  116. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  117. }
  118. public function getDirectDownload(string $path): never {
  119. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  120. }
  121. public function verifyPath(string $path, string $fileName): void {
  122. }
  123. public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): never {
  124. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  125. }
  126. public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): never {
  127. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  128. }
  129. public function acquireLock(string $path, int $type, ILockingProvider $provider): never {
  130. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  131. }
  132. public function releaseLock(string $path, int $type, ILockingProvider $provider): never {
  133. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  134. }
  135. public function changeLock(string $path, int $type, ILockingProvider $provider): never {
  136. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  137. }
  138. public function getAvailability(): never {
  139. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  140. }
  141. public function setAvailability(bool $isAvailable): never {
  142. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  143. }
  144. public function getCache(string $path = '', ?IStorage $storage = null): FailedCache {
  145. return new FailedCache();
  146. }
  147. }