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