You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IStorage.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author J0WI <J0WI@users.noreply.github.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. /**
  28. * Public interface of ownCloud for apps to use.
  29. * Files/Storage interface
  30. */
  31. // use OCP namespace for all classes that are considered public.
  32. // This means that they should be used by apps instead of the internal ownCloud classes
  33. namespace OCP\Files\Storage;
  34. use OCP\Files\Cache\ICache;
  35. use OCP\Files\Cache\IPropagator;
  36. use OCP\Files\Cache\IScanner;
  37. use OCP\Files\Cache\IUpdater;
  38. use OCP\Files\Cache\IWatcher;
  39. use OCP\Files\InvalidPathException;
  40. /**
  41. * Provide a common interface to all different storage options
  42. *
  43. * All paths passed to the storage are relative to the storage and should NOT have a leading slash.
  44. *
  45. * @since 9.0.0
  46. */
  47. interface IStorage {
  48. /**
  49. * $parameters is a free form array with the configuration options needed to construct the storage
  50. *
  51. * @param array $parameters
  52. * @since 9.0.0
  53. */
  54. public function __construct($parameters);
  55. /**
  56. * Get the identifier for the storage,
  57. * the returned id should be the same for every storage object that is created with the same parameters
  58. * and two storage objects with the same id should refer to two storages that display the same files.
  59. *
  60. * @return string
  61. * @since 9.0.0
  62. */
  63. public function getId();
  64. /**
  65. * see https://www.php.net/manual/en/function.mkdir.php
  66. * implementations need to implement a recursive mkdir
  67. *
  68. * @param string $path
  69. * @return bool
  70. * @since 9.0.0
  71. */
  72. public function mkdir($path);
  73. /**
  74. * see https://www.php.net/manual/en/function.rmdir.php
  75. *
  76. * @param string $path
  77. * @return bool
  78. * @since 9.0.0
  79. */
  80. public function rmdir($path);
  81. /**
  82. * see https://www.php.net/manual/en/function.opendir.php
  83. *
  84. * @param string $path
  85. * @return resource|bool
  86. * @since 9.0.0
  87. */
  88. public function opendir($path);
  89. /**
  90. * see https://www.php.net/manual/en/function.is-dir.php
  91. *
  92. * @param string $path
  93. * @return bool
  94. * @since 9.0.0
  95. */
  96. public function is_dir($path);
  97. /**
  98. * see https://www.php.net/manual/en/function.is-file.php
  99. *
  100. * @param string $path
  101. * @return bool
  102. * @since 9.0.0
  103. */
  104. public function is_file($path);
  105. /**
  106. * see https://www.php.net/manual/en/function.stat.php
  107. * only the following keys are required in the result: size and mtime
  108. *
  109. * @param string $path
  110. * @return array|bool
  111. * @since 9.0.0
  112. */
  113. public function stat($path);
  114. /**
  115. * see https://www.php.net/manual/en/function.filetype.php
  116. *
  117. * @param string $path
  118. * @return string|bool
  119. * @since 9.0.0
  120. */
  121. public function filetype($path);
  122. /**
  123. * see https://www.php.net/manual/en/function.filesize.php
  124. * The result for filesize when called on a folder is required to be 0
  125. *
  126. * @param string $path
  127. * @return int|bool
  128. * @since 9.0.0
  129. */
  130. public function filesize($path);
  131. /**
  132. * check if a file can be created in $path
  133. *
  134. * @param string $path
  135. * @return bool
  136. * @since 9.0.0
  137. */
  138. public function isCreatable($path);
  139. /**
  140. * check if a file can be read
  141. *
  142. * @param string $path
  143. * @return bool
  144. * @since 9.0.0
  145. */
  146. public function isReadable($path);
  147. /**
  148. * check if a file can be written to
  149. *
  150. * @param string $path
  151. * @return bool
  152. * @since 9.0.0
  153. */
  154. public function isUpdatable($path);
  155. /**
  156. * check if a file can be deleted
  157. *
  158. * @param string $path
  159. * @return bool
  160. * @since 9.0.0
  161. */
  162. public function isDeletable($path);
  163. /**
  164. * check if a file can be shared
  165. *
  166. * @param string $path
  167. * @return bool
  168. * @since 9.0.0
  169. */
  170. public function isSharable($path);
  171. /**
  172. * get the full permissions of a path.
  173. * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
  174. *
  175. * @param string $path
  176. * @return int
  177. * @since 9.0.0
  178. */
  179. public function getPermissions($path);
  180. /**
  181. * see https://www.php.net/manual/en/function.file_exists.php
  182. *
  183. * @param string $path
  184. * @return bool
  185. * @since 9.0.0
  186. */
  187. public function file_exists($path);
  188. /**
  189. * see https://www.php.net/manual/en/function.filemtime.php
  190. *
  191. * @param string $path
  192. * @return int|bool
  193. * @since 9.0.0
  194. */
  195. public function filemtime($path);
  196. /**
  197. * see https://www.php.net/manual/en/function.file_get_contents.php
  198. *
  199. * @param string $path
  200. * @return string|bool
  201. * @since 9.0.0
  202. */
  203. public function file_get_contents($path);
  204. /**
  205. * see https://www.php.net/manual/en/function.file_put_contents.php
  206. *
  207. * @param string $path
  208. * @param mixed $data
  209. * @return int|false
  210. * @since 9.0.0
  211. */
  212. public function file_put_contents($path, $data);
  213. /**
  214. * see https://www.php.net/manual/en/function.unlink.php
  215. *
  216. * @param string $path
  217. * @return bool
  218. * @since 9.0.0
  219. */
  220. public function unlink($path);
  221. /**
  222. * see https://www.php.net/manual/en/function.rename.php
  223. *
  224. * @param string $path1
  225. * @param string $path2
  226. * @return bool
  227. * @since 9.0.0
  228. */
  229. public function rename($path1, $path2);
  230. /**
  231. * see https://www.php.net/manual/en/function.copy.php
  232. *
  233. * @param string $path1
  234. * @param string $path2
  235. * @return bool
  236. * @since 9.0.0
  237. */
  238. public function copy($path1, $path2);
  239. /**
  240. * see https://www.php.net/manual/en/function.fopen.php
  241. *
  242. * @param string $path
  243. * @param string $mode
  244. * @return resource|bool
  245. * @since 9.0.0
  246. */
  247. public function fopen($path, $mode);
  248. /**
  249. * get the mimetype for a file or folder
  250. * The mimetype for a folder is required to be "httpd/unix-directory"
  251. *
  252. * @param string $path
  253. * @return string|bool
  254. * @since 9.0.0
  255. */
  256. public function getMimeType($path);
  257. /**
  258. * see https://www.php.net/manual/en/function.hash-file.php
  259. *
  260. * @param string $type
  261. * @param string $path
  262. * @param bool $raw
  263. * @return string|bool
  264. * @since 9.0.0
  265. */
  266. public function hash($type, $path, $raw = false);
  267. /**
  268. * see https://www.php.net/manual/en/function.free_space.php
  269. *
  270. * @param string $path
  271. * @return int|bool
  272. * @since 9.0.0
  273. */
  274. public function free_space($path);
  275. /**
  276. * see https://www.php.net/manual/en/function.touch.php
  277. * If the backend does not support the operation, false should be returned
  278. *
  279. * @param string $path
  280. * @param int $mtime
  281. * @return bool
  282. * @since 9.0.0
  283. */
  284. public function touch($path, $mtime = null);
  285. /**
  286. * get the path to a local version of the file.
  287. * The local version of the file can be temporary and doesn't have to be persistent across requests
  288. *
  289. * @param string $path
  290. * @return string|bool
  291. * @since 9.0.0
  292. */
  293. public function getLocalFile($path);
  294. /**
  295. * check if a file or folder has been updated since $time
  296. *
  297. * @param string $path
  298. * @param int $time
  299. * @return bool
  300. * @since 9.0.0
  301. *
  302. * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
  303. * returning true for other changes in the folder is optional
  304. */
  305. public function hasUpdated($path, $time);
  306. /**
  307. * get the ETag for a file or folder
  308. *
  309. * @param string $path
  310. * @return string|bool
  311. * @since 9.0.0
  312. */
  313. public function getETag($path);
  314. /**
  315. * Returns whether the storage is local, which means that files
  316. * are stored on the local filesystem instead of remotely.
  317. * Calling getLocalFile() for local storages should always
  318. * return the local files, whereas for non-local storages
  319. * it might return a temporary file.
  320. *
  321. * @return bool true if the files are stored locally, false otherwise
  322. * @since 9.0.0
  323. */
  324. public function isLocal();
  325. /**
  326. * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
  327. *
  328. * @param string $class
  329. * @return bool
  330. * @since 9.0.0
  331. */
  332. public function instanceOfStorage($class);
  333. /**
  334. * A custom storage implementation can return an url for direct download of a give file.
  335. *
  336. * For now the returned array can hold the parameter url - in future more attributes might follow.
  337. *
  338. * @param string $path
  339. * @return array|bool
  340. * @since 9.0.0
  341. */
  342. public function getDirectDownload($path);
  343. /**
  344. * @param string $path the path of the target folder
  345. * @param string $fileName the name of the file itself
  346. * @return void
  347. * @throws InvalidPathException
  348. * @since 9.0.0
  349. */
  350. public function verifyPath($path, $fileName);
  351. /**
  352. * @param IStorage $sourceStorage
  353. * @param string $sourceInternalPath
  354. * @param string $targetInternalPath
  355. * @return bool
  356. * @since 9.0.0
  357. */
  358. public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath);
  359. /**
  360. * @param IStorage $sourceStorage
  361. * @param string $sourceInternalPath
  362. * @param string $targetInternalPath
  363. * @return bool
  364. * @since 9.0.0
  365. */
  366. public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath);
  367. /**
  368. * Test a storage for availability
  369. *
  370. * @since 9.0.0
  371. * @return bool
  372. */
  373. public function test();
  374. /**
  375. * @since 9.0.0
  376. * @return array [ available, last_checked ]
  377. */
  378. public function getAvailability();
  379. /**
  380. * @since 9.0.0
  381. * @param bool $isAvailable
  382. */
  383. public function setAvailability($isAvailable);
  384. /**
  385. * @param string $path path for which to retrieve the owner
  386. * @since 9.0.0
  387. */
  388. public function getOwner($path);
  389. /**
  390. * @return ICache
  391. * @since 9.0.0
  392. */
  393. public function getCache();
  394. /**
  395. * @return IPropagator
  396. * @since 9.0.0
  397. */
  398. public function getPropagator();
  399. /**
  400. * @return IScanner
  401. * @since 9.0.0
  402. */
  403. public function getScanner();
  404. /**
  405. * @return IUpdater
  406. * @since 9.0.0
  407. */
  408. public function getUpdater();
  409. /**
  410. * @return IWatcher
  411. * @since 9.0.0
  412. */
  413. public function getWatcher();
  414. }