storage.php 11 KB

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