filesystem.php 11 KB

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