OC_Helper.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Ardinis <Ardinis@users.noreply.github.com>
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Bart Visscher <bartv@thisnet.nl>
  8. * @author Björn Schießle <bjoern@schiessle.org>
  9. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  10. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  11. * @author Felix Moeller <mail@felixmoeller.de>
  12. * @author J0WI <J0WI@users.noreply.github.com>
  13. * @author Jakob Sack <mail@jakobsack.de>
  14. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  15. * @author Joas Schilling <coding@schilljs.com>
  16. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  17. * @author Julius Härtl <jus@bitgrid.net>
  18. * @author Lukas Reschke <lukas@statuscode.ch>
  19. * @author Morris Jobke <hey@morrisjobke.de>
  20. * @author Olivier Paroz <github@oparoz.com>
  21. * @author Pellaeon Lin <nfsmwlin@gmail.com>
  22. * @author RealRancor <fisch.666@gmx.de>
  23. * @author Robin Appelman <robin@icewind.nl>
  24. * @author Robin McCorkell <robin@mccorkell.me.uk>
  25. * @author Roeland Jago Douma <roeland@famdouma.nl>
  26. * @author Simon Könnecke <simonkoennecke@gmail.com>
  27. * @author Thomas Müller <thomas.mueller@tmit.eu>
  28. * @author Thomas Tanghus <thomas@tanghus.net>
  29. * @author Vincent Petry <vincent@nextcloud.com>
  30. *
  31. * @license AGPL-3.0
  32. *
  33. * This code is free software: you can redistribute it and/or modify
  34. * it under the terms of the GNU Affero General Public License, version 3,
  35. * as published by the Free Software Foundation.
  36. *
  37. * This program is distributed in the hope that it will be useful,
  38. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40. * GNU Affero General Public License for more details.
  41. *
  42. * You should have received a copy of the GNU Affero General Public License, version 3,
  43. * along with this program. If not, see <http://www.gnu.org/licenses/>
  44. *
  45. */
  46. use bantu\IniGetWrapper\IniGetWrapper;
  47. use OC\Files\Filesystem;
  48. use OCP\Files\Mount\IMountPoint;
  49. use OCP\ICacheFactory;
  50. use OCP\IBinaryFinder;
  51. use OCP\IUser;
  52. use OCP\Util;
  53. use Psr\Log\LoggerInterface;
  54. /**
  55. * Collection of useful functions
  56. */
  57. class OC_Helper {
  58. private static $templateManager;
  59. private static ?ICacheFactory $cacheFactory = null;
  60. private static ?bool $quotaIncludeExternalStorage = null;
  61. /**
  62. * Make a human file size
  63. * @param int|float $bytes file size in bytes
  64. * @return string a human readable file size
  65. *
  66. * Makes 2048 to 2 kB.
  67. */
  68. public static function humanFileSize(int|float $bytes): string {
  69. if ($bytes < 0) {
  70. return "?";
  71. }
  72. if ($bytes < 1024) {
  73. return "$bytes B";
  74. }
  75. $bytes = round($bytes / 1024, 0);
  76. if ($bytes < 1024) {
  77. return "$bytes KB";
  78. }
  79. $bytes = round($bytes / 1024, 1);
  80. if ($bytes < 1024) {
  81. return "$bytes MB";
  82. }
  83. $bytes = round($bytes / 1024, 1);
  84. if ($bytes < 1024) {
  85. return "$bytes GB";
  86. }
  87. $bytes = round($bytes / 1024, 1);
  88. if ($bytes < 1024) {
  89. return "$bytes TB";
  90. }
  91. $bytes = round($bytes / 1024, 1);
  92. return "$bytes PB";
  93. }
  94. /**
  95. * Make a computer file size
  96. * @param string $str file size in human readable format
  97. * @return false|int|float a file size in bytes
  98. *
  99. * Makes 2kB to 2048.
  100. *
  101. * Inspired by: https://www.php.net/manual/en/function.filesize.php#92418
  102. */
  103. public static function computerFileSize(string $str): false|int|float {
  104. $str = strtolower($str);
  105. if (is_numeric($str)) {
  106. return Util::numericToNumber($str);
  107. }
  108. $bytes_array = [
  109. 'b' => 1,
  110. 'k' => 1024,
  111. 'kb' => 1024,
  112. 'mb' => 1024 * 1024,
  113. 'm' => 1024 * 1024,
  114. 'gb' => 1024 * 1024 * 1024,
  115. 'g' => 1024 * 1024 * 1024,
  116. 'tb' => 1024 * 1024 * 1024 * 1024,
  117. 't' => 1024 * 1024 * 1024 * 1024,
  118. 'pb' => 1024 * 1024 * 1024 * 1024 * 1024,
  119. 'p' => 1024 * 1024 * 1024 * 1024 * 1024,
  120. ];
  121. $bytes = (float)$str;
  122. if (preg_match('#([kmgtp]?b?)$#si', $str, $matches) && !empty($bytes_array[$matches[1]])) {
  123. $bytes *= $bytes_array[$matches[1]];
  124. } else {
  125. return false;
  126. }
  127. return Util::numericToNumber(round($bytes));
  128. }
  129. /**
  130. * Recursive copying of folders
  131. * @param string $src source folder
  132. * @param string $dest target folder
  133. * @return void
  134. */
  135. public static function copyr($src, $dest) {
  136. if (is_dir($src)) {
  137. if (!is_dir($dest)) {
  138. mkdir($dest);
  139. }
  140. $files = scandir($src);
  141. foreach ($files as $file) {
  142. if ($file != "." && $file != "..") {
  143. self::copyr("$src/$file", "$dest/$file");
  144. }
  145. }
  146. } elseif (file_exists($src) && !\OC\Files\Filesystem::isFileBlacklisted($src)) {
  147. copy($src, $dest);
  148. }
  149. }
  150. /**
  151. * Recursive deletion of folders
  152. * @param string $dir path to the folder
  153. * @param bool $deleteSelf if set to false only the content of the folder will be deleted
  154. * @return bool
  155. */
  156. public static function rmdirr($dir, $deleteSelf = true) {
  157. if (is_dir($dir)) {
  158. $files = new RecursiveIteratorIterator(
  159. new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
  160. RecursiveIteratorIterator::CHILD_FIRST
  161. );
  162. foreach ($files as $fileInfo) {
  163. /** @var SplFileInfo $fileInfo */
  164. if ($fileInfo->isLink()) {
  165. unlink($fileInfo->getPathname());
  166. } elseif ($fileInfo->isDir()) {
  167. rmdir($fileInfo->getRealPath());
  168. } else {
  169. unlink($fileInfo->getRealPath());
  170. }
  171. }
  172. if ($deleteSelf) {
  173. rmdir($dir);
  174. }
  175. } elseif (file_exists($dir)) {
  176. if ($deleteSelf) {
  177. unlink($dir);
  178. }
  179. }
  180. if (!$deleteSelf) {
  181. return true;
  182. }
  183. return !file_exists($dir);
  184. }
  185. /**
  186. * @deprecated 18.0.0
  187. * @return \OC\Files\Type\TemplateManager
  188. */
  189. public static function getFileTemplateManager() {
  190. if (!self::$templateManager) {
  191. self::$templateManager = new \OC\Files\Type\TemplateManager();
  192. }
  193. return self::$templateManager;
  194. }
  195. /**
  196. * detect if a given program is found in the search PATH
  197. *
  198. * @param string $name
  199. * @param bool $path
  200. * @internal param string $program name
  201. * @internal param string $optional search path, defaults to $PATH
  202. * @return bool true if executable program found in path
  203. */
  204. public static function canExecute($name, $path = false) {
  205. // path defaults to PATH from environment if not set
  206. if ($path === false) {
  207. $path = getenv("PATH");
  208. }
  209. // we look for an executable file of that name
  210. $exts = [""];
  211. $check_fn = "is_executable";
  212. // Default check will be done with $path directories :
  213. $dirs = explode(PATH_SEPARATOR, $path);
  214. // WARNING : We have to check if open_basedir is enabled :
  215. $obd = OC::$server->get(IniGetWrapper::class)->getString('open_basedir');
  216. if ($obd != "none") {
  217. $obd_values = explode(PATH_SEPARATOR, $obd);
  218. if (count($obd_values) > 0 and $obd_values[0]) {
  219. // open_basedir is in effect !
  220. // We need to check if the program is in one of these dirs :
  221. $dirs = $obd_values;
  222. }
  223. }
  224. foreach ($dirs as $dir) {
  225. foreach ($exts as $ext) {
  226. if ($check_fn("$dir/$name" . $ext)) {
  227. return true;
  228. }
  229. }
  230. }
  231. return false;
  232. }
  233. /**
  234. * copy the contents of one stream to another
  235. *
  236. * @param resource $source
  237. * @param resource $target
  238. * @return array the number of bytes copied and result
  239. */
  240. public static function streamCopy($source, $target) {
  241. if (!$source or !$target) {
  242. return [0, false];
  243. }
  244. $bufSize = 8192;
  245. $result = true;
  246. $count = 0;
  247. while (!feof($source)) {
  248. $buf = fread($source, $bufSize);
  249. $bytesWritten = fwrite($target, $buf);
  250. if ($bytesWritten !== false) {
  251. $count += $bytesWritten;
  252. }
  253. // note: strlen is expensive so only use it when necessary,
  254. // on the last block
  255. if ($bytesWritten === false
  256. || ($bytesWritten < $bufSize && $bytesWritten < strlen($buf))
  257. ) {
  258. // write error, could be disk full ?
  259. $result = false;
  260. break;
  261. }
  262. }
  263. return [$count, $result];
  264. }
  265. /**
  266. * Adds a suffix to the name in case the file exists
  267. *
  268. * @param string $path
  269. * @param string $filename
  270. * @return string
  271. */
  272. public static function buildNotExistingFileName($path, $filename) {
  273. $view = \OC\Files\Filesystem::getView();
  274. return self::buildNotExistingFileNameForView($path, $filename, $view);
  275. }
  276. /**
  277. * Adds a suffix to the name in case the file exists
  278. *
  279. * @param string $path
  280. * @param string $filename
  281. * @return string
  282. */
  283. public static function buildNotExistingFileNameForView($path, $filename, \OC\Files\View $view) {
  284. if ($path === '/') {
  285. $path = '';
  286. }
  287. if ($pos = strrpos($filename, '.')) {
  288. $name = substr($filename, 0, $pos);
  289. $ext = substr($filename, $pos);
  290. } else {
  291. $name = $filename;
  292. $ext = '';
  293. }
  294. $newpath = $path . '/' . $filename;
  295. if ($view->file_exists($newpath)) {
  296. if (preg_match_all('/\((\d+)\)/', $name, $matches, PREG_OFFSET_CAPTURE)) {
  297. //Replace the last "(number)" with "(number+1)"
  298. $last_match = count($matches[0]) - 1;
  299. $counter = $matches[1][$last_match][0] + 1;
  300. $offset = $matches[0][$last_match][1];
  301. $match_length = strlen($matches[0][$last_match][0]);
  302. } else {
  303. $counter = 2;
  304. $match_length = 0;
  305. $offset = false;
  306. }
  307. do {
  308. if ($offset) {
  309. //Replace the last "(number)" with "(number+1)"
  310. $newname = substr_replace($name, '(' . $counter . ')', $offset, $match_length);
  311. } else {
  312. $newname = $name . ' (' . $counter . ')';
  313. }
  314. $newpath = $path . '/' . $newname . $ext;
  315. $counter++;
  316. } while ($view->file_exists($newpath));
  317. }
  318. return $newpath;
  319. }
  320. /**
  321. * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
  322. *
  323. * @param array $input The array to work on
  324. * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default)
  325. * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8
  326. * @return array
  327. *
  328. * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
  329. * based on https://www.php.net/manual/en/function.array-change-key-case.php#107715
  330. *
  331. */
  332. public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') {
  333. $case = ($case != MB_CASE_UPPER) ? MB_CASE_LOWER : MB_CASE_UPPER;
  334. $ret = [];
  335. foreach ($input as $k => $v) {
  336. $ret[mb_convert_case($k, $case, $encoding)] = $v;
  337. }
  338. return $ret;
  339. }
  340. /**
  341. * performs a search in a nested array
  342. * @param array $haystack the array to be searched
  343. * @param string $needle the search string
  344. * @param mixed $index optional, only search this key name
  345. * @return mixed the key of the matching field, otherwise false
  346. *
  347. * performs a search in a nested array
  348. *
  349. * taken from https://www.php.net/manual/en/function.array-search.php#97645
  350. */
  351. public static function recursiveArraySearch($haystack, $needle, $index = null) {
  352. $aIt = new RecursiveArrayIterator($haystack);
  353. $it = new RecursiveIteratorIterator($aIt);
  354. while ($it->valid()) {
  355. if (((isset($index) and ($it->key() == $index)) or !isset($index)) and ($it->current() == $needle)) {
  356. return $aIt->key();
  357. }
  358. $it->next();
  359. }
  360. return false;
  361. }
  362. /**
  363. * calculates the maximum upload size respecting system settings, free space and user quota
  364. *
  365. * @param string $dir the current folder where the user currently operates
  366. * @param int|float $freeSpace the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
  367. * @return int|float number of bytes representing
  368. */
  369. public static function maxUploadFilesize($dir, $freeSpace = null) {
  370. if (is_null($freeSpace) || $freeSpace < 0) {
  371. $freeSpace = self::freeSpace($dir);
  372. }
  373. return min($freeSpace, self::uploadLimit());
  374. }
  375. /**
  376. * Calculate free space left within user quota
  377. *
  378. * @param string $dir the current folder where the user currently operates
  379. * @return int|float number of bytes representing
  380. */
  381. public static function freeSpace($dir) {
  382. $freeSpace = \OC\Files\Filesystem::free_space($dir);
  383. if ($freeSpace < \OCP\Files\FileInfo::SPACE_UNLIMITED) {
  384. $freeSpace = max($freeSpace, 0);
  385. return $freeSpace;
  386. } else {
  387. return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
  388. }
  389. }
  390. /**
  391. * Calculate PHP upload limit
  392. *
  393. * @return int|float PHP upload file size limit
  394. */
  395. public static function uploadLimit() {
  396. $ini = \OC::$server->get(IniGetWrapper::class);
  397. $upload_max_filesize = Util::computerFileSize($ini->get('upload_max_filesize')) ?: 0;
  398. $post_max_size = Util::computerFileSize($ini->get('post_max_size')) ?: 0;
  399. if ($upload_max_filesize === 0 && $post_max_size === 0) {
  400. return INF;
  401. } elseif ($upload_max_filesize === 0 || $post_max_size === 0) {
  402. return max($upload_max_filesize, $post_max_size); //only the non 0 value counts
  403. } else {
  404. return min($upload_max_filesize, $post_max_size);
  405. }
  406. }
  407. /**
  408. * Checks if a function is available
  409. *
  410. * @deprecated Since 25.0.0 use \OCP\Util::isFunctionEnabled instead
  411. */
  412. public static function is_function_enabled(string $function_name): bool {
  413. return \OCP\Util::isFunctionEnabled($function_name);
  414. }
  415. /**
  416. * Try to find a program
  417. * @deprecated Since 25.0.0 Use \OC\BinaryFinder directly
  418. */
  419. public static function findBinaryPath(string $program): ?string {
  420. $result = \OCP\Server::get(IBinaryFinder::class)->findBinaryPath($program);
  421. return $result !== false ? $result : null;
  422. }
  423. /**
  424. * Calculate the disc space for the given path
  425. *
  426. * BEWARE: this requires that Util::setupFS() was called
  427. * already !
  428. *
  429. * @param string $path
  430. * @param \OCP\Files\FileInfo $rootInfo (optional)
  431. * @param bool $includeMountPoints whether to include mount points in the size calculation
  432. * @param bool $useCache whether to use the cached quota values
  433. * @return array
  434. * @throws \OCP\Files\NotFoundException
  435. */
  436. public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) {
  437. if (!self::$cacheFactory) {
  438. self::$cacheFactory = \OC::$server->get(ICacheFactory::class);
  439. }
  440. $memcache = self::$cacheFactory->createLocal('storage_info');
  441. // return storage info without adding mount points
  442. if (self::$quotaIncludeExternalStorage === null) {
  443. self::$quotaIncludeExternalStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false);
  444. }
  445. $view = Filesystem::getView();
  446. if (!$view) {
  447. throw new \OCP\Files\NotFoundException();
  448. }
  449. $fullPath = Filesystem::normalizePath($view->getAbsolutePath($path));
  450. $cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude');
  451. if ($useCache) {
  452. $cached = $memcache->get($cacheKey);
  453. if ($cached) {
  454. return $cached;
  455. }
  456. }
  457. if (!$rootInfo) {
  458. $rootInfo = \OC\Files\Filesystem::getFileInfo($path, self::$quotaIncludeExternalStorage ? 'ext' : false);
  459. }
  460. if (!$rootInfo instanceof \OCP\Files\FileInfo) {
  461. throw new \OCP\Files\NotFoundException();
  462. }
  463. $used = $rootInfo->getSize($includeMountPoints);
  464. if ($used < 0) {
  465. $used = 0;
  466. }
  467. $quota = \OCP\Files\FileInfo::SPACE_UNLIMITED;
  468. $mount = $rootInfo->getMountPoint();
  469. $storage = $mount->getStorage();
  470. $sourceStorage = $storage;
  471. if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
  472. self::$quotaIncludeExternalStorage = false;
  473. }
  474. if (self::$quotaIncludeExternalStorage) {
  475. if ($storage->instanceOfStorage('\OC\Files\Storage\Home')
  476. || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')
  477. ) {
  478. /** @var \OC\Files\Storage\Home $storage */
  479. $user = $storage->getUser();
  480. } else {
  481. $user = \OC::$server->getUserSession()->getUser();
  482. }
  483. $quota = OC_Util::getUserQuota($user);
  484. if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
  485. // always get free space / total space from root + mount points
  486. return self::getGlobalStorageInfo($quota, $user, $mount);
  487. }
  488. }
  489. // TODO: need a better way to get total space from storage
  490. if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota')) {
  491. /** @var \OC\Files\Storage\Wrapper\Quota $storage */
  492. $quota = $sourceStorage->getQuota();
  493. }
  494. try {
  495. $free = $sourceStorage->free_space($rootInfo->getInternalPath());
  496. } catch (\Exception $e) {
  497. if ($path === "") {
  498. throw $e;
  499. }
  500. /** @var LoggerInterface $logger */
  501. $logger = \OC::$server->get(LoggerInterface::class);
  502. $logger->warning("Error while getting quota info, using root quota", ['exception' => $e]);
  503. $rootInfo = self::getStorageInfo("");
  504. $memcache->set($cacheKey, $rootInfo, 5 * 60);
  505. return $rootInfo;
  506. }
  507. if ($free >= 0) {
  508. $total = $free + $used;
  509. } else {
  510. $total = $free; //either unknown or unlimited
  511. }
  512. if ($total > 0) {
  513. if ($quota > 0 && $total > $quota) {
  514. $total = $quota;
  515. }
  516. // prevent division by zero or error codes (negative values)
  517. $relative = round(($used / $total) * 10000) / 100;
  518. } else {
  519. $relative = 0;
  520. }
  521. $ownerId = $storage->getOwner($path);
  522. $ownerDisplayName = '';
  523. if ($ownerId) {
  524. $ownerDisplayName = \OC::$server->getUserManager()->getDisplayName($ownerId) ?? '';
  525. }
  526. if (substr_count($mount->getMountPoint(), '/') < 3) {
  527. $mountPoint = '';
  528. } else {
  529. [,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4);
  530. }
  531. $info = [
  532. 'free' => $free,
  533. 'used' => $used,
  534. 'quota' => $quota,
  535. 'total' => $total,
  536. 'relative' => $relative,
  537. 'owner' => $ownerId,
  538. 'ownerDisplayName' => $ownerDisplayName,
  539. 'mountType' => $mount->getMountType(),
  540. 'mountPoint' => trim($mountPoint, '/'),
  541. ];
  542. $memcache->set($cacheKey, $info, 5 * 60);
  543. return $info;
  544. }
  545. /**
  546. * Get storage info including all mount points and quota
  547. */
  548. private static function getGlobalStorageInfo(int|float $quota, IUser $user, IMountPoint $mount): array {
  549. $rootInfo = \OC\Files\Filesystem::getFileInfo('', 'ext');
  550. $used = $rootInfo['size'];
  551. if ($used < 0) {
  552. $used = 0;
  553. }
  554. $total = $quota;
  555. $free = $quota - $used;
  556. if ($total > 0) {
  557. if ($quota > 0 && $total > $quota) {
  558. $total = $quota;
  559. }
  560. // prevent division by zero or error codes (negative values)
  561. $relative = round(($used / $total) * 10000) / 100;
  562. } else {
  563. $relative = 0;
  564. }
  565. if (substr_count($mount->getMountPoint(), '/') < 3) {
  566. $mountPoint = '';
  567. } else {
  568. [,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4);
  569. }
  570. return [
  571. 'free' => $free,
  572. 'used' => $used,
  573. 'total' => $total,
  574. 'relative' => $relative,
  575. 'quota' => $quota,
  576. 'owner' => $user->getUID(),
  577. 'ownerDisplayName' => $user->getDisplayName(),
  578. 'mountType' => $mount->getMountType(),
  579. 'mountPoint' => trim($mountPoint, '/'),
  580. ];
  581. }
  582. public static function clearStorageInfo(string $absolutePath): void {
  583. /** @var ICacheFactory $cacheFactory */
  584. $cacheFactory = \OC::$server->get(ICacheFactory::class);
  585. $memcache = $cacheFactory->createLocal('storage_info');
  586. $cacheKeyPrefix = Filesystem::normalizePath($absolutePath) . '::';
  587. $memcache->remove($cacheKeyPrefix . 'include');
  588. $memcache->remove($cacheKeyPrefix . 'exclude');
  589. }
  590. /**
  591. * Returns whether the config file is set manually to read-only
  592. * @return bool
  593. */
  594. public static function isReadOnlyConfigEnabled() {
  595. return \OC::$server->getConfig()->getSystemValueBool('config_is_read_only', false);
  596. }
  597. }