Filesystem.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Christopher Schäpers <kondou@ts.unde.re>
  8. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  9. * @author Florin Peter <github@florin-peter.de>
  10. * @author Joas Schilling <coding@schilljs.com>
  11. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  12. * @author korelstar <korelstar@users.noreply.github.com>
  13. * @author Lukas Reschke <lukas@statuscode.ch>
  14. * @author Michael Gapczynski <GapczynskiM@gmail.com>
  15. * @author Morris Jobke <hey@morrisjobke.de>
  16. * @author Robin Appelman <robin@icewind.nl>
  17. * @author Robin McCorkell <robin@mccorkell.me.uk>
  18. * @author Roeland Jago Douma <roeland@famdouma.nl>
  19. * @author Sam Tuke <mail@samtuke.com>
  20. * @author Stephan Peijnik <speijnik@anexia-it.com>
  21. * @author Vincent Petry <vincent@nextcloud.com>
  22. *
  23. * @license AGPL-3.0
  24. *
  25. * This code is free software: you can redistribute it and/or modify
  26. * it under the terms of the GNU Affero General Public License, version 3,
  27. * as published by the Free Software Foundation.
  28. *
  29. * This program is distributed in the hope that it will be useful,
  30. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32. * GNU Affero General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU Affero General Public License, version 3,
  35. * along with this program. If not, see <http://www.gnu.org/licenses/>
  36. *
  37. */
  38. namespace OC\Files;
  39. use OCP\Cache\CappedMemoryCache;
  40. use OC\Files\Mount\MountPoint;
  41. use OC\User\NoUserException;
  42. use OCP\EventDispatcher\IEventDispatcher;
  43. use OCP\Files\Events\Node\FilesystemTornDownEvent;
  44. use OCP\Files\Mount\IMountManager;
  45. use OCP\Files\NotFoundException;
  46. use OCP\Files\Storage\IStorageFactory;
  47. use OCP\IUser;
  48. use OCP\IUserManager;
  49. use OCP\IUserSession;
  50. class Filesystem {
  51. private static ?Mount\Manager $mounts = null;
  52. public static bool $loaded = false;
  53. private static ?View $defaultInstance = null;
  54. private static ?CappedMemoryCache $normalizedPathCache = null;
  55. /** @var string[]|null */
  56. private static ?array $blacklist = null;
  57. /**
  58. * classname which used for hooks handling
  59. * used as signalclass in OC_Hooks::emit()
  60. */
  61. public const CLASSNAME = 'OC_Filesystem';
  62. /**
  63. * signalname emitted before file renaming
  64. *
  65. * @param string $oldpath
  66. * @param string $newpath
  67. */
  68. public const signal_rename = 'rename';
  69. /**
  70. * signal emitted after file renaming
  71. *
  72. * @param string $oldpath
  73. * @param string $newpath
  74. */
  75. public const signal_post_rename = 'post_rename';
  76. /**
  77. * signal emitted before file/dir creation
  78. *
  79. * @param string $path
  80. * @param bool $run changing this flag to false in hook handler will cancel event
  81. */
  82. public const signal_create = 'create';
  83. /**
  84. * signal emitted after file/dir creation
  85. *
  86. * @param string $path
  87. * @param bool $run changing this flag to false in hook handler will cancel event
  88. */
  89. public const signal_post_create = 'post_create';
  90. /**
  91. * signal emits before file/dir copy
  92. *
  93. * @param string $oldpath
  94. * @param string $newpath
  95. * @param bool $run changing this flag to false in hook handler will cancel event
  96. */
  97. public const signal_copy = 'copy';
  98. /**
  99. * signal emits after file/dir copy
  100. *
  101. * @param string $oldpath
  102. * @param string $newpath
  103. */
  104. public const signal_post_copy = 'post_copy';
  105. /**
  106. * signal emits before file/dir save
  107. *
  108. * @param string $path
  109. * @param bool $run changing this flag to false in hook handler will cancel event
  110. */
  111. public const signal_write = 'write';
  112. /**
  113. * signal emits after file/dir save
  114. *
  115. * @param string $path
  116. */
  117. public const signal_post_write = 'post_write';
  118. /**
  119. * signal emitted before file/dir update
  120. *
  121. * @param string $path
  122. * @param bool $run changing this flag to false in hook handler will cancel event
  123. */
  124. public const signal_update = 'update';
  125. /**
  126. * signal emitted after file/dir update
  127. *
  128. * @param string $path
  129. * @param bool $run changing this flag to false in hook handler will cancel event
  130. */
  131. public const signal_post_update = 'post_update';
  132. /**
  133. * signal emits when reading file/dir
  134. *
  135. * @param string $path
  136. */
  137. public const signal_read = 'read';
  138. /**
  139. * signal emits when removing file/dir
  140. *
  141. * @param string $path
  142. */
  143. public const signal_delete = 'delete';
  144. /**
  145. * parameters definitions for signals
  146. */
  147. public const signal_param_path = 'path';
  148. public const signal_param_oldpath = 'oldpath';
  149. public const signal_param_newpath = 'newpath';
  150. /**
  151. * run - changing this flag to false in hook handler will cancel event
  152. */
  153. public const signal_param_run = 'run';
  154. public const signal_create_mount = 'create_mount';
  155. public const signal_delete_mount = 'delete_mount';
  156. public const signal_param_mount_type = 'mounttype';
  157. public const signal_param_users = 'users';
  158. private static ?\OC\Files\Storage\StorageFactory $loader = null;
  159. private static bool $logWarningWhenAddingStorageWrapper = true;
  160. /**
  161. * @param bool $shouldLog
  162. * @return bool previous value
  163. * @internal
  164. */
  165. public static function logWarningWhenAddingStorageWrapper(bool $shouldLog): bool {
  166. $previousValue = self::$logWarningWhenAddingStorageWrapper;
  167. self::$logWarningWhenAddingStorageWrapper = $shouldLog;
  168. return $previousValue;
  169. }
  170. /**
  171. * @param string $wrapperName
  172. * @param callable $wrapper
  173. * @param int $priority
  174. */
  175. public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) {
  176. if (self::$logWarningWhenAddingStorageWrapper) {
  177. \OC::$server->getLogger()->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [
  178. 'wrapper' => $wrapperName,
  179. 'app' => 'filesystem',
  180. ]);
  181. }
  182. $mounts = self::getMountManager()->getAll();
  183. if (!self::getLoader()->addStorageWrapper($wrapperName, $wrapper, $priority, $mounts)) {
  184. // do not re-wrap if storage with this name already existed
  185. return;
  186. }
  187. }
  188. /**
  189. * Returns the storage factory
  190. *
  191. * @return IStorageFactory
  192. */
  193. public static function getLoader() {
  194. if (!self::$loader) {
  195. self::$loader = \OC::$server->get(IStorageFactory::class);
  196. }
  197. return self::$loader;
  198. }
  199. /**
  200. * Returns the mount manager
  201. */
  202. public static function getMountManager(): Mount\Manager {
  203. self::initMountManager();
  204. assert(self::$mounts !== null);
  205. return self::$mounts;
  206. }
  207. /**
  208. * get the mountpoint of the storage object for a path
  209. * ( note: because a storage is not always mounted inside the fakeroot, the
  210. * returned mountpoint is relative to the absolute root of the filesystem
  211. * and doesn't take the chroot into account )
  212. *
  213. * @param string $path
  214. * @return string
  215. */
  216. public static function getMountPoint($path) {
  217. if (!self::$mounts) {
  218. \OC_Util::setupFS();
  219. }
  220. $mount = self::$mounts->find($path);
  221. return $mount->getMountPoint();
  222. }
  223. /**
  224. * get a list of all mount points in a directory
  225. *
  226. * @param string $path
  227. * @return string[]
  228. */
  229. public static function getMountPoints($path) {
  230. if (!self::$mounts) {
  231. \OC_Util::setupFS();
  232. }
  233. $result = [];
  234. $mounts = self::$mounts->findIn($path);
  235. foreach ($mounts as $mount) {
  236. $result[] = $mount->getMountPoint();
  237. }
  238. return $result;
  239. }
  240. /**
  241. * get the storage mounted at $mountPoint
  242. *
  243. * @param string $mountPoint
  244. * @return \OC\Files\Storage\Storage|null
  245. */
  246. public static function getStorage($mountPoint) {
  247. $mount = self::getMountManager()->find($mountPoint);
  248. return $mount->getStorage();
  249. }
  250. /**
  251. * @param string $id
  252. * @return Mount\MountPoint[]
  253. */
  254. public static function getMountByStorageId($id) {
  255. return self::getMountManager()->findByStorageId($id);
  256. }
  257. /**
  258. * @param int $id
  259. * @return Mount\MountPoint[]
  260. */
  261. public static function getMountByNumericId($id) {
  262. return self::getMountManager()->findByNumericId($id);
  263. }
  264. /**
  265. * resolve a path to a storage and internal path
  266. *
  267. * @param string $path
  268. * @return array{?\OCP\Files\Storage\IStorage, string} an array consisting of the storage and the internal path
  269. */
  270. public static function resolvePath($path): array {
  271. $mount = self::getMountManager()->find($path);
  272. return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
  273. }
  274. public static function init(string|IUser|null $user, string $root): bool {
  275. if (self::$defaultInstance) {
  276. return false;
  277. }
  278. self::initInternal($root);
  279. //load custom mount config
  280. self::initMountPoints($user);
  281. return true;
  282. }
  283. public static function initInternal(string $root): bool {
  284. if (self::$defaultInstance) {
  285. return false;
  286. }
  287. self::getLoader();
  288. self::$defaultInstance = new View($root);
  289. /** @var IEventDispatcher $eventDispatcher */
  290. $eventDispatcher = \OC::$server->get(IEventDispatcher::class);
  291. $eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
  292. self::$defaultInstance = null;
  293. self::$loaded = false;
  294. });
  295. self::initMountManager();
  296. self::$loaded = true;
  297. return true;
  298. }
  299. public static function initMountManager(): void {
  300. if (!self::$mounts) {
  301. self::$mounts = \OC::$server->get(IMountManager::class);
  302. }
  303. }
  304. /**
  305. * Initialize system and personal mount points for a user
  306. *
  307. * @throws \OC\User\NoUserException if the user is not available
  308. */
  309. public static function initMountPoints(string|IUser|null $user = ''): void {
  310. /** @var IUserManager $userManager */
  311. $userManager = \OC::$server->get(IUserManager::class);
  312. $userObject = ($user instanceof IUser) ? $user : $userManager->get($user);
  313. if ($userObject) {
  314. /** @var SetupManager $setupManager */
  315. $setupManager = \OC::$server->get(SetupManager::class);
  316. $setupManager->setupForUser($userObject);
  317. } else {
  318. throw new NoUserException();
  319. }
  320. }
  321. /**
  322. * Get the default filesystem view
  323. */
  324. public static function getView(): ?View {
  325. if (!self::$defaultInstance) {
  326. /** @var IUserSession $session */
  327. $session = \OC::$server->get(IUserSession::class);
  328. $user = $session->getUser();
  329. if ($user) {
  330. $userDir = '/' . $user->getUID() . '/files';
  331. self::initInternal($userDir);
  332. }
  333. }
  334. return self::$defaultInstance;
  335. }
  336. /**
  337. * tear down the filesystem, removing all storage providers
  338. */
  339. public static function tearDown() {
  340. \OC_Util::tearDownFS();
  341. }
  342. /**
  343. * get the relative path of the root data directory for the current user
  344. *
  345. * @return ?string
  346. *
  347. * Returns path like /admin/files
  348. */
  349. public static function getRoot() {
  350. if (!self::$defaultInstance) {
  351. return null;
  352. }
  353. return self::$defaultInstance->getRoot();
  354. }
  355. /**
  356. * mount an \OC\Files\Storage\Storage in our virtual filesystem
  357. *
  358. * @param \OC\Files\Storage\Storage|string $class
  359. * @param array $arguments
  360. * @param string $mountpoint
  361. */
  362. public static function mount($class, $arguments, $mountpoint) {
  363. if (!self::$mounts) {
  364. \OC_Util::setupFS();
  365. }
  366. $mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader());
  367. self::$mounts->addMount($mount);
  368. }
  369. /**
  370. * return the path to a local version of the file
  371. * we need this because we can't know if a file is stored local or not from
  372. * outside the filestorage and for some purposes a local file is needed
  373. */
  374. public static function getLocalFile(string $path): string|false {
  375. return self::$defaultInstance->getLocalFile($path);
  376. }
  377. /**
  378. * return path to file which reflects one visible in browser
  379. *
  380. * @param string $path
  381. * @return string
  382. */
  383. public static function getLocalPath($path) {
  384. $datadir = \OC_User::getHome(\OC_User::getUser()) . '/files';
  385. $newpath = $path;
  386. if (strncmp($newpath, $datadir, strlen($datadir)) == 0) {
  387. $newpath = substr($path, strlen($datadir));
  388. }
  389. return $newpath;
  390. }
  391. /**
  392. * check if the requested path is valid
  393. *
  394. * @param string $path
  395. * @return bool
  396. */
  397. public static function isValidPath($path) {
  398. $path = self::normalizePath($path);
  399. if (!$path || $path[0] !== '/') {
  400. $path = '/' . $path;
  401. }
  402. if (strpos($path, '/../') !== false || strrchr($path, '/') === '/..') {
  403. return false;
  404. }
  405. return true;
  406. }
  407. /**
  408. * @param string $filename
  409. * @return bool
  410. */
  411. public static function isFileBlacklisted($filename) {
  412. $filename = self::normalizePath($filename);
  413. if (self::$blacklist === null) {
  414. self::$blacklist = \OC::$server->getConfig()->getSystemValue('blacklisted_files', ['.htaccess']);
  415. }
  416. $filename = strtolower(basename($filename));
  417. return in_array($filename, self::$blacklist);
  418. }
  419. /**
  420. * check if the directory should be ignored when scanning
  421. * NOTE: the special directories . and .. would cause never ending recursion
  422. *
  423. * @param string $dir
  424. * @return boolean
  425. */
  426. public static function isIgnoredDir($dir) {
  427. if ($dir === '.' || $dir === '..') {
  428. return true;
  429. }
  430. return false;
  431. }
  432. /**
  433. * following functions are equivalent to their php builtin equivalents for arguments/return values.
  434. */
  435. public static function mkdir($path) {
  436. return self::$defaultInstance->mkdir($path);
  437. }
  438. public static function rmdir($path) {
  439. return self::$defaultInstance->rmdir($path);
  440. }
  441. public static function is_dir($path) {
  442. return self::$defaultInstance->is_dir($path);
  443. }
  444. public static function is_file($path) {
  445. return self::$defaultInstance->is_file($path);
  446. }
  447. public static function stat($path) {
  448. return self::$defaultInstance->stat($path);
  449. }
  450. public static function filetype($path) {
  451. return self::$defaultInstance->filetype($path);
  452. }
  453. public static function filesize($path) {
  454. return self::$defaultInstance->filesize($path);
  455. }
  456. public static function readfile($path) {
  457. return self::$defaultInstance->readfile($path);
  458. }
  459. public static function isCreatable($path) {
  460. return self::$defaultInstance->isCreatable($path);
  461. }
  462. public static function isReadable($path) {
  463. return self::$defaultInstance->isReadable($path);
  464. }
  465. public static function isUpdatable($path) {
  466. return self::$defaultInstance->isUpdatable($path);
  467. }
  468. public static function isDeletable($path) {
  469. return self::$defaultInstance->isDeletable($path);
  470. }
  471. public static function isSharable($path) {
  472. return self::$defaultInstance->isSharable($path);
  473. }
  474. public static function file_exists($path) {
  475. return self::$defaultInstance->file_exists($path);
  476. }
  477. public static function filemtime($path) {
  478. return self::$defaultInstance->filemtime($path);
  479. }
  480. public static function touch($path, $mtime = null) {
  481. return self::$defaultInstance->touch($path, $mtime);
  482. }
  483. /**
  484. * @return string|false
  485. */
  486. public static function file_get_contents($path) {
  487. return self::$defaultInstance->file_get_contents($path);
  488. }
  489. public static function file_put_contents($path, $data) {
  490. return self::$defaultInstance->file_put_contents($path, $data);
  491. }
  492. public static function unlink($path) {
  493. return self::$defaultInstance->unlink($path);
  494. }
  495. public static function rename($source, $target) {
  496. return self::$defaultInstance->rename($source, $target);
  497. }
  498. public static function copy($source, $target) {
  499. return self::$defaultInstance->copy($source, $target);
  500. }
  501. public static function fopen($path, $mode) {
  502. return self::$defaultInstance->fopen($path, $mode);
  503. }
  504. /**
  505. * @param string $path
  506. * @throws \OCP\Files\InvalidPathException
  507. */
  508. public static function toTmpFile($path): string|false {
  509. return self::$defaultInstance->toTmpFile($path);
  510. }
  511. public static function fromTmpFile($tmpFile, $path) {
  512. return self::$defaultInstance->fromTmpFile($tmpFile, $path);
  513. }
  514. public static function getMimeType($path) {
  515. return self::$defaultInstance->getMimeType($path);
  516. }
  517. public static function hash($type, $path, $raw = false) {
  518. return self::$defaultInstance->hash($type, $path, $raw);
  519. }
  520. public static function free_space($path = '/') {
  521. return self::$defaultInstance->free_space($path);
  522. }
  523. public static function search($query) {
  524. return self::$defaultInstance->search($query);
  525. }
  526. /**
  527. * @param string $query
  528. */
  529. public static function searchByMime($query) {
  530. return self::$defaultInstance->searchByMime($query);
  531. }
  532. /**
  533. * @param string|int $tag name or tag id
  534. * @param string $userId owner of the tags
  535. * @return FileInfo[] array or file info
  536. */
  537. public static function searchByTag($tag, $userId) {
  538. return self::$defaultInstance->searchByTag($tag, $userId);
  539. }
  540. /**
  541. * check if a file or folder has been updated since $time
  542. *
  543. * @param string $path
  544. * @param int $time
  545. * @return bool
  546. */
  547. public static function hasUpdated($path, $time) {
  548. return self::$defaultInstance->hasUpdated($path, $time);
  549. }
  550. /**
  551. * Fix common problems with a file path
  552. *
  553. * @param string $path
  554. * @param bool $stripTrailingSlash whether to strip the trailing slash
  555. * @param bool $isAbsolutePath whether the given path is absolute
  556. * @param bool $keepUnicode true to disable unicode normalization
  557. * @psalm-taint-escape file
  558. * @return string
  559. */
  560. public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) {
  561. /**
  562. * FIXME: This is a workaround for existing classes and files which call
  563. * this function with another type than a valid string. This
  564. * conversion should get removed as soon as all existing
  565. * function calls have been fixed.
  566. */
  567. $path = (string)$path;
  568. if ($path === '') {
  569. return '/';
  570. }
  571. if (is_null(self::$normalizedPathCache)) {
  572. self::$normalizedPathCache = new CappedMemoryCache(2048);
  573. }
  574. $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath, $keepUnicode]);
  575. if ($cacheKey && isset(self::$normalizedPathCache[$cacheKey])) {
  576. return self::$normalizedPathCache[$cacheKey];
  577. }
  578. //normalize unicode if possible
  579. if (!$keepUnicode) {
  580. $path = \OC_Util::normalizeUnicode($path);
  581. }
  582. //add leading slash, if it is already there we strip it anyway
  583. $path = '/' . $path;
  584. $patterns = [
  585. '#\\\\#s', // no windows style '\\' slashes
  586. '#/\.(/\.)*/#s', // remove '/./'
  587. '#\//+#s', // remove sequence of slashes
  588. '#/\.$#s', // remove trailing '/.'
  589. ];
  590. do {
  591. $count = 0;
  592. $path = preg_replace($patterns, '/', $path, -1, $count);
  593. } while ($count > 0);
  594. //remove trailing slash
  595. if ($stripTrailingSlash && strlen($path) > 1) {
  596. $path = rtrim($path, '/');
  597. }
  598. self::$normalizedPathCache[$cacheKey] = $path;
  599. return $path;
  600. }
  601. /**
  602. * get the filesystem info
  603. *
  604. * @param string $path
  605. * @param bool|string $includeMountPoints whether to add mountpoint sizes,
  606. * defaults to true
  607. * @return \OC\Files\FileInfo|false False if file does not exist
  608. */
  609. public static function getFileInfo($path, $includeMountPoints = true) {
  610. return self::getView()->getFileInfo($path, $includeMountPoints);
  611. }
  612. /**
  613. * change file metadata
  614. *
  615. * @param string $path
  616. * @param array $data
  617. * @return int
  618. *
  619. * returns the fileid of the updated file
  620. */
  621. public static function putFileInfo($path, $data) {
  622. return self::$defaultInstance->putFileInfo($path, $data);
  623. }
  624. /**
  625. * get the content of a directory
  626. *
  627. * @param string $directory path under datadirectory
  628. * @param string $mimetype_filter limit returned content to this mimetype or mimepart
  629. * @return \OC\Files\FileInfo[]
  630. */
  631. public static function getDirectoryContent($directory, $mimetype_filter = '') {
  632. return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
  633. }
  634. /**
  635. * Get the path of a file by id
  636. *
  637. * Note that the resulting path is not guaranteed to be unique for the id, multiple paths can point to the same file
  638. *
  639. * @param int $id
  640. * @throws NotFoundException
  641. * @return string
  642. */
  643. public static function getPath($id) {
  644. return self::$defaultInstance->getPath($id);
  645. }
  646. /**
  647. * Get the owner for a file or folder
  648. *
  649. * @param string $path
  650. * @return string
  651. */
  652. public static function getOwner($path) {
  653. return self::$defaultInstance->getOwner($path);
  654. }
  655. /**
  656. * get the ETag for a file or folder
  657. */
  658. public static function getETag(string $path): string|false {
  659. return self::$defaultInstance->getETag($path);
  660. }
  661. }