Storage.php 11 KB

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