FailedStorage.php 7.2 KB

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