FailedStorage.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 $params ['exception' => \Exception]
  20. */
  21. public function __construct($params) {
  22. $this->e = $params['exception'];
  23. if (!$this->e) {
  24. throw new \InvalidArgumentException('Missing "exception" argument in FailedStorage constructor');
  25. }
  26. }
  27. public function getId() {
  28. // we can't return anything sane here
  29. return 'failedstorage';
  30. }
  31. public function mkdir($path) {
  32. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  33. }
  34. public function rmdir($path) {
  35. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  36. }
  37. public function opendir($path) {
  38. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  39. }
  40. public function is_dir($path) {
  41. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  42. }
  43. public function is_file($path) {
  44. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  45. }
  46. public function stat($path) {
  47. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  48. }
  49. public function filetype($path) {
  50. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  51. }
  52. public function filesize($path): false|int|float {
  53. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  54. }
  55. public function isCreatable($path) {
  56. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  57. }
  58. public function isReadable($path) {
  59. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  60. }
  61. public function isUpdatable($path) {
  62. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  63. }
  64. public function isDeletable($path) {
  65. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  66. }
  67. public function isSharable($path) {
  68. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  69. }
  70. public function getPermissions($path) {
  71. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  72. }
  73. public function file_exists($path) {
  74. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  75. }
  76. public function filemtime($path) {
  77. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  78. }
  79. public function file_get_contents($path) {
  80. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  81. }
  82. public function file_put_contents($path, $data) {
  83. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  84. }
  85. public function unlink($path) {
  86. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  87. }
  88. public function rename($source, $target) {
  89. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  90. }
  91. public function copy($source, $target) {
  92. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  93. }
  94. public function fopen($path, $mode) {
  95. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  96. }
  97. public function getMimeType($path) {
  98. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  99. }
  100. public function hash($type, $path, $raw = false) {
  101. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  102. }
  103. public function free_space($path) {
  104. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  105. }
  106. public function search($query) {
  107. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  108. }
  109. public function touch($path, $mtime = null) {
  110. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  111. }
  112. public function getLocalFile($path) {
  113. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  114. }
  115. public function hasUpdated($path, $time) {
  116. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  117. }
  118. public function getETag($path) {
  119. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  120. }
  121. public function getDirectDownload($path) {
  122. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  123. }
  124. public function verifyPath($path, $fileName) {
  125. return true;
  126. }
  127. public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
  128. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  129. }
  130. public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
  131. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  132. }
  133. public function acquireLock($path, $type, ILockingProvider $provider) {
  134. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  135. }
  136. public function releaseLock($path, $type, ILockingProvider $provider) {
  137. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  138. }
  139. public function changeLock($path, $type, ILockingProvider $provider) {
  140. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  141. }
  142. public function getAvailability() {
  143. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  144. }
  145. public function setAvailability($isAvailable) {
  146. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  147. }
  148. public function getCache($path = '', $storage = null) {
  149. return new FailedCache();
  150. }
  151. }