filesystem.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. /**
  3. * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. /**
  9. * Class for abstraction of filesystem functions
  10. * This class won't call any filesystem functions for itself but but will pass them to the correct OC_Filestorage object
  11. * this class should also handle all the file permission related stuff
  12. *
  13. * Hooks provided:
  14. * read(path)
  15. * write(path, &run)
  16. * post_write(path)
  17. * create(path, &run) (when a file is created, both create and write will be emitted in that order)
  18. * post_create(path)
  19. * delete(path, &run)
  20. * post_delete(path)
  21. * rename(oldpath,newpath, &run)
  22. * post_rename(oldpath,newpath)
  23. * copy(oldpath,newpath, &run) (if the newpath doesn't exists yes, copy, create and write will be emitted in that order)
  24. * post_rename(oldpath,newpath)
  25. *
  26. * the &run parameter can be set to false to prevent the operation from occurring
  27. */
  28. /**
  29. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  30. */
  31. class OC_Filesystem {
  32. /**
  33. * get the mountpoint of the storage object for a path
  34. * ( note: because a storage is not always mounted inside the fakeroot, the
  35. * returned mountpoint is relative to the absolute root of the filesystem
  36. * and doesn't take the chroot into account )
  37. *
  38. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  39. * @param string $path
  40. * @return string
  41. */
  42. static public function getMountPoint($path) {
  43. return \OC\Files\Filesystem::getMountPoint($path);
  44. }
  45. /**
  46. * resolve a path to a storage and internal path
  47. *
  48. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  49. * @param string $path
  50. * @return array consisting of the storage and the internal path
  51. */
  52. static public function resolvePath($path) {
  53. return \OC\Files\Filesystem::resolvePath($path);
  54. }
  55. /**
  56. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  57. */
  58. static public function init($user, $root) {
  59. return \OC\Files\Filesystem::init($user, $root);
  60. }
  61. /**
  62. * get the default filesystem view
  63. *
  64. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  65. * @return \OC\Files\View
  66. */
  67. static public function getView() {
  68. return \OC\Files\Filesystem::getView();
  69. }
  70. /**
  71. * tear down the filesystem, removing all storage providers
  72. *
  73. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  74. */
  75. static public function tearDown() {
  76. \OC\Files\Filesystem::tearDown();
  77. }
  78. /**
  79. * @brief get the relative path of the root data directory for the current user
  80. * @return string
  81. *
  82. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  83. * Returns path like /admin/files
  84. */
  85. static public function getRoot() {
  86. return \OC\Files\Filesystem::getRoot();
  87. }
  88. /**
  89. * clear all mounts and storage backends
  90. *
  91. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  92. */
  93. public static function clearMounts() {
  94. \OC\Files\Filesystem::clearMounts();
  95. }
  96. /**
  97. * mount an \OC\Files\Storage\Storage in our virtual filesystem
  98. *
  99. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  100. * @param \OC\Files\Storage\Storage $class
  101. * @param array $arguments
  102. * @param string $mountpoint
  103. */
  104. static public function mount($class, $arguments, $mountpoint) {
  105. \OC\Files\Filesystem::mount($class, $arguments, $mountpoint);
  106. }
  107. /**
  108. * return the path to a local version of the file
  109. * we need this because we can't know if a file is stored local or not from
  110. * outside the filestorage and for some purposes a local file is needed
  111. *
  112. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  113. * @param string $path
  114. * @return string
  115. */
  116. static public function getLocalFile($path) {
  117. return \OC\Files\Filesystem::getLocalFile($path);
  118. }
  119. /**
  120. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  121. * @param string $path
  122. * @return string
  123. */
  124. static public function getLocalFolder($path) {
  125. return \OC\Files\Filesystem::getLocalFolder($path);
  126. }
  127. /**
  128. * return path to file which reflects one visible in browser
  129. *
  130. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  131. * @param string $path
  132. * @return string
  133. */
  134. static public function getLocalPath($path) {
  135. return \OC\Files\Filesystem::getLocalPath($path);
  136. }
  137. /**
  138. * check if the requested path is valid
  139. *
  140. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  141. * @param string $path
  142. * @return bool
  143. */
  144. static public function isValidPath($path) {
  145. return \OC\Files\Filesystem::isValidPath($path);
  146. }
  147. /**
  148. * checks if a file is blacklisted for storage in the filesystem
  149. * Listens to write and rename hooks
  150. *
  151. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  152. * @param array $data from hook
  153. */
  154. static public function isBlacklisted($data) {
  155. \OC\Files\Filesystem::isBlacklisted($data);
  156. }
  157. /**
  158. * following functions are equivalent to their php builtin equivalents for arguments/return values.
  159. *
  160. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  161. */
  162. static public function mkdir($path) {
  163. return \OC\Files\Filesystem::mkdir($path);
  164. }
  165. /**
  166. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  167. */
  168. static public function rmdir($path) {
  169. return \OC\Files\Filesystem::rmdir($path);
  170. }
  171. /**
  172. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  173. */
  174. static public function opendir($path) {
  175. return \OC\Files\Filesystem::opendir($path);
  176. }
  177. /**
  178. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  179. */
  180. static public function readdir($path) {
  181. return \OC\Files\Filesystem::readdir($path);
  182. }
  183. /**
  184. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  185. */
  186. static public function is_dir($path) {
  187. return \OC\Files\Filesystem::is_dir($path);
  188. }
  189. /**
  190. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  191. */
  192. static public function is_file($path) {
  193. return \OC\Files\Filesystem::is_file($path);
  194. }
  195. /**
  196. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  197. */
  198. static public function stat($path) {
  199. return \OC\Files\Filesystem::stat($path);
  200. }
  201. /**
  202. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  203. */
  204. static public function filetype($path) {
  205. return \OC\Files\Filesystem::filetype($path);
  206. }
  207. /**
  208. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  209. */
  210. static public function filesize($path) {
  211. return \OC\Files\Filesystem::filesize($path);
  212. }
  213. /**
  214. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  215. */
  216. static public function readfile($path) {
  217. return \OC\Files\Filesystem::readfile($path);
  218. }
  219. /**
  220. * @deprecated Replaced by isReadable() as part of CRUDS
  221. */
  222. static public function is_readable($path) {
  223. return \OC\Files\Filesystem::isReadable($path);
  224. }
  225. /**
  226. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  227. */
  228. static public function isCreatable($path) {
  229. return \OC\Files\Filesystem::isCreatable($path);
  230. }
  231. /**
  232. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  233. */
  234. static public function isReadable($path) {
  235. return \OC\Files\Filesystem::isReadable($path);
  236. }
  237. /**
  238. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  239. */
  240. static public function isUpdatable($path) {
  241. return \OC\Files\Filesystem::isUpdatable($path);
  242. }
  243. /**
  244. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  245. */
  246. static public function isDeletable($path) {
  247. return \OC\Files\Filesystem::isDeletable($path);
  248. }
  249. /**
  250. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  251. */
  252. static public function isSharable($path) {
  253. return \OC\Files\Filesystem::isSharable($path);
  254. }
  255. /**
  256. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  257. */
  258. static public function file_exists($path) {
  259. return \OC\Files\Filesystem::file_exists($path);
  260. }
  261. /**
  262. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  263. */
  264. static public function filemtime($path) {
  265. return \OC\Files\Filesystem::filemtime($path);
  266. }
  267. /**
  268. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  269. */
  270. static public function touch($path, $mtime = null) {
  271. return \OC\Files\Filesystem::touch($path, $mtime);
  272. }
  273. /**
  274. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  275. */
  276. static public function file_get_contents($path) {
  277. return \OC\Files\Filesystem::file_get_contents($path);
  278. }
  279. /**
  280. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  281. */
  282. static public function file_put_contents($path, $data) {
  283. return \OC\Files\Filesystem::file_put_contents($path, $data);
  284. }
  285. /**
  286. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  287. */
  288. static public function unlink($path) {
  289. return \OC\Files\Filesystem::unlink($path);
  290. }
  291. /**
  292. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  293. */
  294. static public function rename($path1, $path2) {
  295. return \OC\Files\Filesystem::rename($path1, $path2);
  296. }
  297. /**
  298. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  299. */
  300. static public function copy($path1, $path2) {
  301. return \OC\Files\Filesystem::copy($path1, $path2);
  302. }
  303. /**
  304. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  305. */
  306. static public function fopen($path, $mode) {
  307. return \OC\Files\Filesystem::fopen($path, $mode);
  308. }
  309. /**
  310. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  311. */
  312. static public function toTmpFile($path) {
  313. return \OC\Files\Filesystem::toTmpFile($path);
  314. }
  315. /**
  316. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  317. */
  318. static public function fromTmpFile($tmpFile, $path) {
  319. return \OC\Files\Filesystem::fromTmpFile($tmpFile, $path);
  320. }
  321. /**
  322. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  323. */
  324. static public function getMimeType($path) {
  325. return \OC\Files\Filesystem::getMimeType($path);
  326. }
  327. /**
  328. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  329. */
  330. static public function hash($type, $path, $raw = false) {
  331. return \OC\Files\Filesystem::hash($type, $path, $raw);
  332. }
  333. /**
  334. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  335. */
  336. static public function free_space($path = '/') {
  337. return \OC\Files\Filesystem::free_space($path);
  338. }
  339. /**
  340. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  341. */
  342. static public function search($query) {
  343. return \OC\Files\Filesystem::search($query);
  344. }
  345. /**
  346. * check if a file or folder has been updated since $time
  347. *
  348. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  349. * @param string $path
  350. * @param int $time
  351. * @return bool
  352. */
  353. static public function hasUpdated($path, $time) {
  354. return \OC\Files\Filesystem::hasUpdated($path, $time);
  355. }
  356. /**
  357. * normalize a path
  358. *
  359. * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
  360. * @param string $path
  361. * @param bool $stripTrailingSlash
  362. * @return string
  363. */
  364. public static function normalizePath($path, $stripTrailingSlash = true) {
  365. return \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash);
  366. }
  367. }