FailedStorage.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 Vincent Petry <pvince81@owncloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Files\Storage;
  26. use OC\Files\Cache\FailedCache;
  27. use OCP\Files\Storage\IStorage;
  28. use \OCP\Lock\ILockingProvider;
  29. use \OCP\Files\StorageNotAvailableException;
  30. /**
  31. * Storage placeholder to represent a missing precondition, storage unavailable
  32. */
  33. class FailedStorage extends Common {
  34. /** @var \Exception */
  35. protected $e;
  36. /**
  37. * @param array $params ['exception' => \Exception]
  38. */
  39. public function __construct($params) {
  40. $this->e = $params['exception'];
  41. if (!$this->e) {
  42. throw new \InvalidArgumentException('Missing "exception" argument in FailedStorage constructor');
  43. }
  44. }
  45. public function getId() {
  46. // we can't return anything sane here
  47. return 'failedstorage';
  48. }
  49. public function mkdir($path) {
  50. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  51. }
  52. public function rmdir($path) {
  53. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  54. }
  55. public function opendir($path) {
  56. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  57. }
  58. public function is_dir($path) {
  59. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  60. }
  61. public function is_file($path) {
  62. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  63. }
  64. public function stat($path) {
  65. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  66. }
  67. public function filetype($path) {
  68. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  69. }
  70. public function filesize($path) {
  71. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  72. }
  73. public function isCreatable($path) {
  74. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  75. }
  76. public function isReadable($path) {
  77. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  78. }
  79. public function isUpdatable($path) {
  80. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  81. }
  82. public function isDeletable($path) {
  83. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  84. }
  85. public function isSharable($path) {
  86. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  87. }
  88. public function getPermissions($path) {
  89. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  90. }
  91. public function file_exists($path) {
  92. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  93. }
  94. public function filemtime($path) {
  95. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  96. }
  97. public function file_get_contents($path) {
  98. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  99. }
  100. public function file_put_contents($path, $data) {
  101. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  102. }
  103. public function unlink($path) {
  104. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  105. }
  106. public function rename($path1, $path2) {
  107. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  108. }
  109. public function copy($path1, $path2) {
  110. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  111. }
  112. public function fopen($path, $mode) {
  113. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  114. }
  115. public function getMimeType($path) {
  116. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  117. }
  118. public function hash($type, $path, $raw = false) {
  119. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  120. }
  121. public function free_space($path) {
  122. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  123. }
  124. public function search($query) {
  125. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  126. }
  127. public function touch($path, $mtime = null) {
  128. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  129. }
  130. public function getLocalFile($path) {
  131. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  132. }
  133. public function getLocalFolder($path) {
  134. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  135. }
  136. public function hasUpdated($path, $time) {
  137. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  138. }
  139. public function getETag($path) {
  140. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  141. }
  142. public function getDirectDownload($path) {
  143. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  144. }
  145. public function verifyPath($path, $fileName) {
  146. return true;
  147. }
  148. public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) {
  149. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  150. }
  151. public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
  152. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  153. }
  154. public function acquireLock($path, $type, ILockingProvider $provider) {
  155. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  156. }
  157. public function releaseLock($path, $type, ILockingProvider $provider) {
  158. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  159. }
  160. public function changeLock($path, $type, ILockingProvider $provider) {
  161. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  162. }
  163. public function getAvailability() {
  164. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  165. }
  166. public function setAvailability($isAvailable) {
  167. throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e);
  168. }
  169. public function getCache($path = '', $storage = null) {
  170. return new FailedCache();
  171. }
  172. }