FailedStorage.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Robin McCorkell <robin@mccorkell.me.uk>
  8. * @author Roeland Jago Douma <roeland@famdouma.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 OC\Files\Storage;
  27. use OC\Files\Cache\FailedCache;
  28. use OCP\Files\Storage\IStorage;
  29. use OCP\Files\StorageNotAvailableException;
  30. use OCP\Lock\ILockingProvider;
  31. /**
  32. * Storage placeholder to represent a missing precondition, storage unavailable
  33. */
  34. class FailedStorage extends Common {
  35. /** @var \Exception */
  36. protected $e;
  37. /**
  38. * @param array $params ['exception' => \Exception]
  39. */
  40. public function __construct($params) {
  41. $this->e = $params['exception'];
  42. if (!$this->e) {
  43. throw new \InvalidArgumentException('Missing "exception" argument in FailedStorage constructor');
  44. }
  45. }
  46. public function getId() {
  47. // we can't return anything sane here
  48. return 'failedstorage';
  49. }
  50. public function mkdir($path) {
  51. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  52. }
  53. public function rmdir($path) {
  54. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  55. }
  56. public function opendir($path) {
  57. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  58. }
  59. public function is_dir($path) {
  60. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  61. }
  62. public function is_file($path) {
  63. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  64. }
  65. public function stat($path) {
  66. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  67. }
  68. public function filetype($path) {
  69. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  70. }
  71. public function filesize($path): false|int|float {
  72. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  73. }
  74. public function isCreatable($path) {
  75. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  76. }
  77. public function isReadable($path) {
  78. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  79. }
  80. public function isUpdatable($path) {
  81. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  82. }
  83. public function isDeletable($path) {
  84. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  85. }
  86. public function isSharable($path) {
  87. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  88. }
  89. public function getPermissions($path) {
  90. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  91. }
  92. public function file_exists($path) {
  93. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  94. }
  95. public function filemtime($path) {
  96. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  97. }
  98. public function file_get_contents($path) {
  99. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  100. }
  101. public function file_put_contents($path, $data) {
  102. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  103. }
  104. public function unlink($path) {
  105. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  106. }
  107. public function rename($source, $target) {
  108. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  109. }
  110. public function copy($source, $target) {
  111. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  112. }
  113. public function fopen($path, $mode) {
  114. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  115. }
  116. public function getMimeType($path) {
  117. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  118. }
  119. public function hash($type, $path, $raw = false) {
  120. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  121. }
  122. public function free_space($path) {
  123. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  124. }
  125. public function search($query) {
  126. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  127. }
  128. public function touch($path, $mtime = null) {
  129. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  130. }
  131. public function getLocalFile($path) {
  132. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  133. }
  134. public function getLocalFolder($path) {
  135. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  136. }
  137. public function hasUpdated($path, $time) {
  138. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  139. }
  140. public function getETag($path) {
  141. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  142. }
  143. public function getDirectDownload($path) {
  144. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  145. }
  146. public function verifyPath($path, $fileName) {
  147. return true;
  148. }
  149. public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
  150. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  151. }
  152. public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
  153. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  154. }
  155. public function acquireLock($path, $type, ILockingProvider $provider) {
  156. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  157. }
  158. public function releaseLock($path, $type, ILockingProvider $provider) {
  159. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  160. }
  161. public function changeLock($path, $type, ILockingProvider $provider) {
  162. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  163. }
  164. public function getAvailability() {
  165. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  166. }
  167. public function setAvailability($isAvailable) {
  168. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  169. }
  170. public function getCache($path = '', $storage = null) {
  171. return new FailedCache();
  172. }
  173. }