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.

Storage.php 11KB

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