storage.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. /**
  3. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  4. * @author Michael Roth <michael.roth@rz.uni-augsburg.de>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Robin McCorkell <robin@mccorkell.me.uk>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. * @author Vincent Petry <pvince81@owncloud.com>
  10. *
  11. * @copyright Copyright (c) 2016, ownCloud, Inc.
  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;
  34. use OCP\Files\Storage\IStorage;
  35. use OCP\Lock\ILockingProvider;
  36. /**
  37. * Provide a common interface to all different storage options
  38. *
  39. * All paths passed to the storage are relative to the storage and should NOT have a leading slash.
  40. *
  41. * @since 6.0.0
  42. * @deprecated 9.0.0 use \OCP\Files\Storage\IStorage instead
  43. */
  44. interface Storage extends IStorage {
  45. /**
  46. * $parameters is a free form array with the configuration options needed to construct the storage
  47. *
  48. * @param array $parameters
  49. * @since 6.0.0
  50. */
  51. public function __construct($parameters);
  52. /**
  53. * Get the identifier for the storage,
  54. * the returned id should be the same for every storage object that is created with the same parameters
  55. * and two storage objects with the same id should refer to two storages that display the same files.
  56. *
  57. * @return string
  58. * @since 6.0.0
  59. */
  60. public function getId();
  61. /**
  62. * see http://php.net/manual/en/function.mkdir.php
  63. * implementations need to implement a recursive mkdir
  64. *
  65. * @param string $path
  66. * @return bool
  67. * @since 6.0.0
  68. */
  69. public function mkdir($path);
  70. /**
  71. * see http://php.net/manual/en/function.rmdir.php
  72. *
  73. * @param string $path
  74. * @return bool
  75. * @since 6.0.0
  76. */
  77. public function rmdir($path);
  78. /**
  79. * see http://php.net/manual/en/function.opendir.php
  80. *
  81. * @param string $path
  82. * @return resource|false
  83. * @since 6.0.0
  84. */
  85. public function opendir($path);
  86. /**
  87. * see http://php.net/manual/en/function.is-dir.php
  88. *
  89. * @param string $path
  90. * @return bool
  91. * @since 6.0.0
  92. */
  93. public function is_dir($path);
  94. /**
  95. * see http://php.net/manual/en/function.is-file.php
  96. *
  97. * @param string $path
  98. * @return bool
  99. * @since 6.0.0
  100. */
  101. public function is_file($path);
  102. /**
  103. * see http://php.net/manual/en/function.stat.php
  104. * only the following keys are required in the result: size and mtime
  105. *
  106. * @param string $path
  107. * @return array|false
  108. * @since 6.0.0
  109. */
  110. public function stat($path);
  111. /**
  112. * see http://php.net/manual/en/function.filetype.php
  113. *
  114. * @param string $path
  115. * @return string|false
  116. * @since 6.0.0
  117. */
  118. public function filetype($path);
  119. /**
  120. * see http://php.net/manual/en/function.filesize.php
  121. * The result for filesize when called on a folder is required to be 0
  122. *
  123. * @param string $path
  124. * @return int|false
  125. * @since 6.0.0
  126. */
  127. public function filesize($path);
  128. /**
  129. * check if a file can be created in $path
  130. *
  131. * @param string $path
  132. * @return bool
  133. * @since 6.0.0
  134. */
  135. public function isCreatable($path);
  136. /**
  137. * check if a file can be read
  138. *
  139. * @param string $path
  140. * @return bool
  141. * @since 6.0.0
  142. */
  143. public function isReadable($path);
  144. /**
  145. * check if a file can be written to
  146. *
  147. * @param string $path
  148. * @return bool
  149. * @since 6.0.0
  150. */
  151. public function isUpdatable($path);
  152. /**
  153. * check if a file can be deleted
  154. *
  155. * @param string $path
  156. * @return bool
  157. * @since 6.0.0
  158. */
  159. public function isDeletable($path);
  160. /**
  161. * check if a file can be shared
  162. *
  163. * @param string $path
  164. * @return bool
  165. * @since 6.0.0
  166. */
  167. public function isSharable($path);
  168. /**
  169. * get the full permissions of a path.
  170. * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php
  171. *
  172. * @param string $path
  173. * @return int
  174. * @since 6.0.0
  175. */
  176. public function getPermissions($path);
  177. /**
  178. * see http://php.net/manual/en/function.file_exists.php
  179. *
  180. * @param string $path
  181. * @return bool
  182. * @since 6.0.0
  183. */
  184. public function file_exists($path);
  185. /**
  186. * see http://php.net/manual/en/function.filemtime.php
  187. *
  188. * @param string $path
  189. * @return int|false
  190. * @since 6.0.0
  191. */
  192. public function filemtime($path);
  193. /**
  194. * see http://php.net/manual/en/function.file_get_contents.php
  195. *
  196. * @param string $path
  197. * @return string|false
  198. * @since 6.0.0
  199. */
  200. public function file_get_contents($path);
  201. /**
  202. * see http://php.net/manual/en/function.file_put_contents.php
  203. *
  204. * @param string $path
  205. * @param string $data
  206. * @return bool
  207. * @since 6.0.0
  208. */
  209. public function file_put_contents($path, $data);
  210. /**
  211. * see http://php.net/manual/en/function.unlink.php
  212. *
  213. * @param string $path
  214. * @return bool
  215. * @since 6.0.0
  216. */
  217. public function unlink($path);
  218. /**
  219. * see http://php.net/manual/en/function.rename.php
  220. *
  221. * @param string $path1
  222. * @param string $path2
  223. * @return bool
  224. * @since 6.0.0
  225. */
  226. public function rename($path1, $path2);
  227. /**
  228. * see http://php.net/manual/en/function.copy.php
  229. *
  230. * @param string $path1
  231. * @param string $path2
  232. * @return bool
  233. * @since 6.0.0
  234. */
  235. public function copy($path1, $path2);
  236. /**
  237. * see http://php.net/manual/en/function.fopen.php
  238. *
  239. * @param string $path
  240. * @param string $mode
  241. * @return resource|false
  242. * @since 6.0.0
  243. */
  244. public function fopen($path, $mode);
  245. /**
  246. * get the mimetype for a file or folder
  247. * The mimetype for a folder is required to be "httpd/unix-directory"
  248. *
  249. * @param string $path
  250. * @return string|false
  251. * @since 6.0.0
  252. */
  253. public function getMimeType($path);
  254. /**
  255. * see http://php.net/manual/en/function.hash-file.php
  256. *
  257. * @param string $type
  258. * @param string $path
  259. * @param bool $raw
  260. * @return string|false
  261. * @since 6.0.0
  262. */
  263. public function hash($type, $path, $raw = false);
  264. /**
  265. * see http://php.net/manual/en/function.free_space.php
  266. *
  267. * @param string $path
  268. * @return int|false
  269. * @since 6.0.0
  270. */
  271. public function free_space($path);
  272. /**
  273. * search for occurrences of $query in file names
  274. *
  275. * @param string $query
  276. * @return array|false
  277. * @since 6.0.0
  278. */
  279. public function search($query);
  280. /**
  281. * see http://php.net/manual/en/function.touch.php
  282. * If the backend does not support the operation, false should be returned
  283. *
  284. * @param string $path
  285. * @param int $mtime
  286. * @return bool
  287. * @since 6.0.0
  288. */
  289. public function touch($path, $mtime = null);
  290. /**
  291. * get the path to a local version of the file.
  292. * The local version of the file can be temporary and doesn't have to be persistent across requests
  293. *
  294. * @param string $path
  295. * @return string|false
  296. * @since 6.0.0
  297. */
  298. public function getLocalFile($path);
  299. /**
  300. * check if a file or folder has been updated since $time
  301. *
  302. * @param string $path
  303. * @param int $time
  304. * @return bool
  305. * @since 6.0.0
  306. *
  307. * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed.
  308. * returning true for other changes in the folder is optional
  309. */
  310. public function hasUpdated($path, $time);
  311. /**
  312. * get the ETag for a file or folder
  313. *
  314. * @param string $path
  315. * @return string|false
  316. * @since 6.0.0
  317. */
  318. public function getETag($path);
  319. /**
  320. * Returns whether the storage is local, which means that files
  321. * are stored on the local filesystem instead of remotely.
  322. * Calling getLocalFile() for local storages should always
  323. * return the local files, whereas for non-local storages
  324. * it might return a temporary file.
  325. *
  326. * @return bool true if the files are stored locally, false otherwise
  327. * @since 7.0.0
  328. */
  329. public function isLocal();
  330. /**
  331. * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class
  332. *
  333. * @param string $class
  334. * @return bool
  335. * @since 7.0.0
  336. */
  337. public function instanceOfStorage($class);
  338. /**
  339. * A custom storage implementation can return an url for direct download of a give file.
  340. *
  341. * For now the returned array can hold the parameter url - in future more attributes might follow.
  342. *
  343. * @param string $path
  344. * @return array|false
  345. * @since 8.0.0
  346. */
  347. public function getDirectDownload($path);
  348. /**
  349. * @param string $path the path of the target folder
  350. * @param string $fileName the name of the file itself
  351. * @return void
  352. * @throws InvalidPathException
  353. * @since 8.1.0
  354. */
  355. public function verifyPath($path, $fileName);
  356. /**
  357. * @param \OCP\Files\Storage $sourceStorage
  358. * @param string $sourceInternalPath
  359. * @param string $targetInternalPath
  360. * @return bool
  361. * @since 8.1.0
  362. */
  363. public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath);
  364. /**
  365. * @param \OCP\Files\Storage $sourceStorage
  366. * @param string $sourceInternalPath
  367. * @param string $targetInternalPath
  368. * @return bool
  369. * @since 8.1.0
  370. */
  371. public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath);
  372. /**
  373. * @param string $path The path of the file to acquire the lock for
  374. * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
  375. * @param \OCP\Lock\ILockingProvider $provider
  376. * @throws \OCP\Lock\LockedException
  377. * @since 8.1.0
  378. */
  379. public function acquireLock($path, $type, ILockingProvider $provider);
  380. /**
  381. * @param string $path The path of the file to acquire the lock for
  382. * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
  383. * @param \OCP\Lock\ILockingProvider $provider
  384. * @since 8.1.0
  385. */
  386. public function releaseLock($path, $type, ILockingProvider $provider);
  387. /**
  388. * @param string $path The path of the file to change the lock for
  389. * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
  390. * @param \OCP\Lock\ILockingProvider $provider
  391. * @throws \OCP\Lock\LockedException
  392. * @since 8.1.0
  393. */
  394. public function changeLock($path, $type, ILockingProvider $provider);
  395. /**
  396. * Test a storage for availability
  397. *
  398. * @since 8.2.0
  399. * @return bool
  400. */
  401. public function test();
  402. /**
  403. * @since 8.2.0
  404. * @return array [ available, last_checked ]
  405. */
  406. public function getAvailability();
  407. /**
  408. * @since 8.2.0
  409. * @param bool $isAvailable
  410. */
  411. public function setAvailability($isAvailable);
  412. }