nodefs-handler.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. 'use strict';
  2. const fs = require('fs');
  3. const sysPath = require('path');
  4. const { promisify } = require('util');
  5. const isBinaryPath = require('is-binary-path');
  6. const {
  7. isWindows,
  8. isLinux,
  9. EMPTY_FN,
  10. EMPTY_STR,
  11. KEY_LISTENERS,
  12. KEY_ERR,
  13. KEY_RAW,
  14. HANDLER_KEYS,
  15. EV_CHANGE,
  16. EV_ADD,
  17. EV_ADD_DIR,
  18. EV_ERROR,
  19. STR_DATA,
  20. STR_END,
  21. BRACE_START,
  22. STAR
  23. } = require('./constants');
  24. const THROTTLE_MODE_WATCH = 'watch';
  25. const open = promisify(fs.open);
  26. const stat = promisify(fs.stat);
  27. const lstat = promisify(fs.lstat);
  28. const close = promisify(fs.close);
  29. const fsrealpath = promisify(fs.realpath);
  30. const statMethods = { lstat, stat };
  31. // TODO: emit errors properly. Example: EMFILE on Macos.
  32. const foreach = (val, fn) => {
  33. if (val instanceof Set) {
  34. val.forEach(fn);
  35. } else {
  36. fn(val);
  37. }
  38. };
  39. const addAndConvert = (main, prop, item) => {
  40. let container = main[prop];
  41. if (!(container instanceof Set)) {
  42. main[prop] = container = new Set([container]);
  43. }
  44. container.add(item);
  45. };
  46. const clearItem = cont => key => {
  47. const set = cont[key];
  48. if (set instanceof Set) {
  49. set.clear();
  50. } else {
  51. delete cont[key];
  52. }
  53. };
  54. const delFromSet = (main, prop, item) => {
  55. const container = main[prop];
  56. if (container instanceof Set) {
  57. container.delete(item);
  58. } else if (container === item) {
  59. delete main[prop];
  60. }
  61. };
  62. const isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
  63. /**
  64. * @typedef {String} Path
  65. */
  66. // fs_watch helpers
  67. // object to hold per-process fs_watch instances
  68. // (may be shared across chokidar FSWatcher instances)
  69. /**
  70. * @typedef {Object} FsWatchContainer
  71. * @property {Set} listeners
  72. * @property {Set} errHandlers
  73. * @property {Set} rawEmitters
  74. * @property {fs.FSWatcher=} watcher
  75. * @property {Boolean=} watcherUnusable
  76. */
  77. /**
  78. * @type {Map<String,FsWatchContainer>}
  79. */
  80. const FsWatchInstances = new Map();
  81. /**
  82. * Instantiates the fs_watch interface
  83. * @param {String} path to be watched
  84. * @param {Object} options to be passed to fs_watch
  85. * @param {Function} listener main event handler
  86. * @param {Function} errHandler emits info about errors
  87. * @param {Function} emitRaw emits raw event data
  88. * @returns {fs.FSWatcher} new fsevents instance
  89. */
  90. function createFsWatchInstance(path, options, listener, errHandler, emitRaw) {
  91. const handleEvent = (rawEvent, evPath) => {
  92. listener(path);
  93. emitRaw(rawEvent, evPath, {watchedPath: path});
  94. // emit based on events occurring for files from a directory's watcher in
  95. // case the file's watcher misses it (and rely on throttling to de-dupe)
  96. if (evPath && path !== evPath) {
  97. fsWatchBroadcast(
  98. sysPath.resolve(path, evPath), KEY_LISTENERS, sysPath.join(path, evPath)
  99. );
  100. }
  101. };
  102. try {
  103. return fs.watch(path, options, handleEvent);
  104. } catch (error) {
  105. errHandler(error);
  106. }
  107. }
  108. /**
  109. * Helper for passing fs_watch event data to a collection of listeners
  110. * @param {Path} fullPath absolute path bound to fs_watch instance
  111. * @param {String} type listener type
  112. * @param {*=} val1 arguments to be passed to listeners
  113. * @param {*=} val2
  114. * @param {*=} val3
  115. */
  116. const fsWatchBroadcast = (fullPath, type, val1, val2, val3) => {
  117. const cont = FsWatchInstances.get(fullPath);
  118. if (!cont) return;
  119. foreach(cont[type], (listener) => {
  120. listener(val1, val2, val3);
  121. });
  122. };
  123. /**
  124. * Instantiates the fs_watch interface or binds listeners
  125. * to an existing one covering the same file system entry
  126. * @param {String} path
  127. * @param {String} fullPath absolute path
  128. * @param {Object} options to be passed to fs_watch
  129. * @param {Object} handlers container for event listener functions
  130. */
  131. const setFsWatchListener = (path, fullPath, options, handlers) => {
  132. const {listener, errHandler, rawEmitter} = handlers;
  133. let cont = FsWatchInstances.get(fullPath);
  134. /** @type {fs.FSWatcher=} */
  135. let watcher;
  136. if (!options.persistent) {
  137. watcher = createFsWatchInstance(
  138. path, options, listener, errHandler, rawEmitter
  139. );
  140. return watcher.close.bind(watcher);
  141. }
  142. if (cont) {
  143. addAndConvert(cont, KEY_LISTENERS, listener);
  144. addAndConvert(cont, KEY_ERR, errHandler);
  145. addAndConvert(cont, KEY_RAW, rawEmitter);
  146. } else {
  147. watcher = createFsWatchInstance(
  148. path,
  149. options,
  150. fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
  151. errHandler, // no need to use broadcast here
  152. fsWatchBroadcast.bind(null, fullPath, KEY_RAW)
  153. );
  154. if (!watcher) return;
  155. watcher.on(EV_ERROR, async (error) => {
  156. const broadcastErr = fsWatchBroadcast.bind(null, fullPath, KEY_ERR);
  157. cont.watcherUnusable = true; // documented since Node 10.4.1
  158. // Workaround for https://github.com/joyent/node/issues/4337
  159. if (isWindows && error.code === 'EPERM') {
  160. try {
  161. const fd = await open(path, 'r');
  162. await close(fd);
  163. broadcastErr(error);
  164. } catch (err) {}
  165. } else {
  166. broadcastErr(error);
  167. }
  168. });
  169. cont = {
  170. listeners: listener,
  171. errHandlers: errHandler,
  172. rawEmitters: rawEmitter,
  173. watcher
  174. };
  175. FsWatchInstances.set(fullPath, cont);
  176. }
  177. // const index = cont.listeners.indexOf(listener);
  178. // removes this instance's listeners and closes the underlying fs_watch
  179. // instance if there are no more listeners left
  180. return () => {
  181. delFromSet(cont, KEY_LISTENERS, listener);
  182. delFromSet(cont, KEY_ERR, errHandler);
  183. delFromSet(cont, KEY_RAW, rawEmitter);
  184. if (isEmptySet(cont.listeners)) {
  185. // Check to protect against issue gh-730.
  186. // if (cont.watcherUnusable) {
  187. cont.watcher.close();
  188. // }
  189. FsWatchInstances.delete(fullPath);
  190. HANDLER_KEYS.forEach(clearItem(cont));
  191. cont.watcher = undefined;
  192. Object.freeze(cont);
  193. }
  194. };
  195. };
  196. // fs_watchFile helpers
  197. // object to hold per-process fs_watchFile instances
  198. // (may be shared across chokidar FSWatcher instances)
  199. const FsWatchFileInstances = new Map();
  200. /**
  201. * Instantiates the fs_watchFile interface or binds listeners
  202. * to an existing one covering the same file system entry
  203. * @param {String} path to be watched
  204. * @param {String} fullPath absolute path
  205. * @param {Object} options options to be passed to fs_watchFile
  206. * @param {Object} handlers container for event listener functions
  207. * @returns {Function} closer
  208. */
  209. const setFsWatchFileListener = (path, fullPath, options, handlers) => {
  210. const {listener, rawEmitter} = handlers;
  211. let cont = FsWatchFileInstances.get(fullPath);
  212. /* eslint-disable no-unused-vars, prefer-destructuring */
  213. let listeners = new Set();
  214. let rawEmitters = new Set();
  215. const copts = cont && cont.options;
  216. if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
  217. // "Upgrade" the watcher to persistence or a quicker interval.
  218. // This creates some unlikely edge case issues if the user mixes
  219. // settings in a very weird way, but solving for those cases
  220. // doesn't seem worthwhile for the added complexity.
  221. listeners = cont.listeners;
  222. rawEmitters = cont.rawEmitters;
  223. fs.unwatchFile(fullPath);
  224. cont = undefined;
  225. }
  226. /* eslint-enable no-unused-vars, prefer-destructuring */
  227. if (cont) {
  228. addAndConvert(cont, KEY_LISTENERS, listener);
  229. addAndConvert(cont, KEY_RAW, rawEmitter);
  230. } else {
  231. // TODO
  232. // listeners.add(listener);
  233. // rawEmitters.add(rawEmitter);
  234. cont = {
  235. listeners: listener,
  236. rawEmitters: rawEmitter,
  237. options,
  238. watcher: fs.watchFile(fullPath, options, (curr, prev) => {
  239. foreach(cont.rawEmitters, (rawEmitter) => {
  240. rawEmitter(EV_CHANGE, fullPath, {curr, prev});
  241. });
  242. const currmtime = curr.mtimeMs;
  243. if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
  244. foreach(cont.listeners, (listener) => listener(path, curr));
  245. }
  246. })
  247. };
  248. FsWatchFileInstances.set(fullPath, cont);
  249. }
  250. // const index = cont.listeners.indexOf(listener);
  251. // Removes this instance's listeners and closes the underlying fs_watchFile
  252. // instance if there are no more listeners left.
  253. return () => {
  254. delFromSet(cont, KEY_LISTENERS, listener);
  255. delFromSet(cont, KEY_RAW, rawEmitter);
  256. if (isEmptySet(cont.listeners)) {
  257. FsWatchFileInstances.delete(fullPath);
  258. fs.unwatchFile(fullPath);
  259. cont.options = cont.watcher = undefined;
  260. Object.freeze(cont);
  261. }
  262. };
  263. };
  264. /**
  265. * @mixin
  266. */
  267. class NodeFsHandler {
  268. /**
  269. * @param {import("../index").FSWatcher} fsW
  270. */
  271. constructor(fsW) {
  272. this.fsw = fsW;
  273. this._boundHandleError = (error) => fsW._handleError(error);
  274. }
  275. /**
  276. * Watch file for changes with fs_watchFile or fs_watch.
  277. * @param {String} path to file or dir
  278. * @param {Function} listener on fs change
  279. * @returns {Function} closer for the watcher instance
  280. */
  281. _watchWithNodeFs(path, listener) {
  282. const opts = this.fsw.options;
  283. const directory = sysPath.dirname(path);
  284. const basename = sysPath.basename(path);
  285. const parent = this.fsw._getWatchedDir(directory);
  286. parent.add(basename);
  287. const absolutePath = sysPath.resolve(path);
  288. const options = {persistent: opts.persistent};
  289. if (!listener) listener = EMPTY_FN;
  290. let closer;
  291. if (opts.usePolling) {
  292. options.interval = opts.enableBinaryInterval && isBinaryPath(basename) ?
  293. opts.binaryInterval : opts.interval;
  294. closer = setFsWatchFileListener(path, absolutePath, options, {
  295. listener,
  296. rawEmitter: this.fsw._emitRaw
  297. });
  298. } else {
  299. closer = setFsWatchListener(path, absolutePath, options, {
  300. listener,
  301. errHandler: this._boundHandleError,
  302. rawEmitter: this.fsw._emitRaw
  303. });
  304. }
  305. return closer;
  306. }
  307. /**
  308. * Watch a file and emit add event if warranted.
  309. * @param {Path} file Path
  310. * @param {fs.Stats} stats result of fs_stat
  311. * @param {Boolean} initialAdd was the file added at watch instantiation?
  312. * @returns {Function} closer for the watcher instance
  313. */
  314. _handleFile(file, stats, initialAdd) {
  315. if (this.fsw.closed) {
  316. return;
  317. }
  318. const dirname = sysPath.dirname(file);
  319. const basename = sysPath.basename(file);
  320. const parent = this.fsw._getWatchedDir(dirname);
  321. // stats is always present
  322. let prevStats = stats;
  323. // if the file is already being watched, do nothing
  324. if (parent.has(basename)) return;
  325. const listener = async (path, newStats) => {
  326. if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
  327. if (!newStats || newStats.mtimeMs === 0) {
  328. try {
  329. const newStats = await stat(file);
  330. if (this.fsw.closed) return;
  331. // Check that change event was not fired because of changed only accessTime.
  332. const at = newStats.atimeMs;
  333. const mt = newStats.mtimeMs;
  334. if (!at || at <= mt || mt !== prevStats.mtimeMs) {
  335. this.fsw._emit(EV_CHANGE, file, newStats);
  336. }
  337. if (isLinux && prevStats.ino !== newStats.ino) {
  338. this.fsw._closeFile(path)
  339. prevStats = newStats;
  340. this.fsw._addPathCloser(path, this._watchWithNodeFs(file, listener));
  341. } else {
  342. prevStats = newStats;
  343. }
  344. } catch (error) {
  345. // Fix issues where mtime is null but file is still present
  346. this.fsw._remove(dirname, basename);
  347. }
  348. // add is about to be emitted if file not already tracked in parent
  349. } else if (parent.has(basename)) {
  350. // Check that change event was not fired because of changed only accessTime.
  351. const at = newStats.atimeMs;
  352. const mt = newStats.mtimeMs;
  353. if (!at || at <= mt || mt !== prevStats.mtimeMs) {
  354. this.fsw._emit(EV_CHANGE, file, newStats);
  355. }
  356. prevStats = newStats;
  357. }
  358. }
  359. // kick off the watcher
  360. const closer = this._watchWithNodeFs(file, listener);
  361. // emit an add event if we're supposed to
  362. if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
  363. if (!this.fsw._throttle(EV_ADD, file, 0)) return;
  364. this.fsw._emit(EV_ADD, file, stats);
  365. }
  366. return closer;
  367. }
  368. /**
  369. * Handle symlinks encountered while reading a dir.
  370. * @param {Object} entry returned by readdirp
  371. * @param {String} directory path of dir being read
  372. * @param {String} path of this item
  373. * @param {String} item basename of this item
  374. * @returns {Promise<Boolean>} true if no more processing is needed for this entry.
  375. */
  376. async _handleSymlink(entry, directory, path, item) {
  377. if (this.fsw.closed) {
  378. return;
  379. }
  380. const full = entry.fullPath;
  381. const dir = this.fsw._getWatchedDir(directory);
  382. if (!this.fsw.options.followSymlinks) {
  383. // watch symlink directly (don't follow) and detect changes
  384. this.fsw._incrReadyCount();
  385. const linkPath = await fsrealpath(path);
  386. if (this.fsw.closed) return;
  387. if (dir.has(item)) {
  388. if (this.fsw._symlinkPaths.get(full) !== linkPath) {
  389. this.fsw._symlinkPaths.set(full, linkPath);
  390. this.fsw._emit(EV_CHANGE, path, entry.stats);
  391. }
  392. } else {
  393. dir.add(item);
  394. this.fsw._symlinkPaths.set(full, linkPath);
  395. this.fsw._emit(EV_ADD, path, entry.stats);
  396. }
  397. this.fsw._emitReady();
  398. return true;
  399. }
  400. // don't follow the same symlink more than once
  401. if (this.fsw._symlinkPaths.has(full)) {
  402. return true;
  403. }
  404. this.fsw._symlinkPaths.set(full, true);
  405. }
  406. _handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
  407. // Normalize the directory name on Windows
  408. directory = sysPath.join(directory, EMPTY_STR);
  409. if (!wh.hasGlob) {
  410. throttler = this.fsw._throttle('readdir', directory, 1000);
  411. if (!throttler) return;
  412. }
  413. const previous = this.fsw._getWatchedDir(wh.path);
  414. const current = new Set();
  415. let stream = this.fsw._readdirp(directory, {
  416. fileFilter: entry => wh.filterPath(entry),
  417. directoryFilter: entry => wh.filterDir(entry),
  418. depth: 0
  419. }).on(STR_DATA, async (entry) => {
  420. if (this.fsw.closed) {
  421. stream = undefined;
  422. return;
  423. }
  424. const item = entry.path;
  425. let path = sysPath.join(directory, item);
  426. current.add(item);
  427. if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path, item)) {
  428. return;
  429. }
  430. if (this.fsw.closed) {
  431. stream = undefined;
  432. return;
  433. }
  434. // Files that present in current directory snapshot
  435. // but absent in previous are added to watch list and
  436. // emit `add` event.
  437. if (item === target || !target && !previous.has(item)) {
  438. this.fsw._incrReadyCount();
  439. // ensure relativeness of path is preserved in case of watcher reuse
  440. path = sysPath.join(dir, sysPath.relative(dir, path));
  441. this._addToNodeFs(path, initialAdd, wh, depth + 1);
  442. }
  443. }).on(EV_ERROR, this._boundHandleError);
  444. return new Promise(resolve =>
  445. stream.once(STR_END, () => {
  446. if (this.fsw.closed) {
  447. stream = undefined;
  448. return;
  449. }
  450. const wasThrottled = throttler ? throttler.clear() : false;
  451. resolve();
  452. // Files that absent in current directory snapshot
  453. // but present in previous emit `remove` event
  454. // and are removed from @watched[directory].
  455. previous.getChildren().filter((item) => {
  456. return item !== directory &&
  457. !current.has(item) &&
  458. // in case of intersecting globs;
  459. // a path may have been filtered out of this readdir, but
  460. // shouldn't be removed because it matches a different glob
  461. (!wh.hasGlob || wh.filterPath({
  462. fullPath: sysPath.resolve(directory, item)
  463. }));
  464. }).forEach((item) => {
  465. this.fsw._remove(directory, item);
  466. });
  467. stream = undefined;
  468. // one more time for any missed in case changes came in extremely quickly
  469. if (wasThrottled) this._handleRead(directory, false, wh, target, dir, depth, throttler);
  470. })
  471. );
  472. }
  473. /**
  474. * Read directory to add / remove files from `@watched` list and re-read it on change.
  475. * @param {String} dir fs path
  476. * @param {fs.Stats} stats
  477. * @param {Boolean} initialAdd
  478. * @param {Number} depth relative to user-supplied path
  479. * @param {String} target child path targeted for watch
  480. * @param {Object} wh Common watch helpers for this path
  481. * @param {String} realpath
  482. * @returns {Promise<Function>} closer for the watcher instance.
  483. */
  484. async _handleDir(dir, stats, initialAdd, depth, target, wh, realpath) {
  485. const parentDir = this.fsw._getWatchedDir(sysPath.dirname(dir));
  486. const tracked = parentDir.has(sysPath.basename(dir));
  487. if (!(initialAdd && this.fsw.options.ignoreInitial) && !target && !tracked) {
  488. if (!wh.hasGlob || wh.globFilter(dir)) this.fsw._emit(EV_ADD_DIR, dir, stats);
  489. }
  490. // ensure dir is tracked (harmless if redundant)
  491. parentDir.add(sysPath.basename(dir));
  492. this.fsw._getWatchedDir(dir);
  493. let throttler;
  494. let closer;
  495. const oDepth = this.fsw.options.depth;
  496. if ((oDepth == null || depth <= oDepth) && !this.fsw._symlinkPaths.has(realpath)) {
  497. if (!target) {
  498. await this._handleRead(dir, initialAdd, wh, target, dir, depth, throttler);
  499. if (this.fsw.closed) return;
  500. }
  501. closer = this._watchWithNodeFs(dir, (dirPath, stats) => {
  502. // if current directory is removed, do nothing
  503. if (stats && stats.mtimeMs === 0) return;
  504. this._handleRead(dirPath, false, wh, target, dir, depth, throttler);
  505. });
  506. }
  507. return closer;
  508. }
  509. /**
  510. * Handle added file, directory, or glob pattern.
  511. * Delegates call to _handleFile / _handleDir after checks.
  512. * @param {String} path to file or ir
  513. * @param {Boolean} initialAdd was the file added at watch instantiation?
  514. * @param {Object} priorWh depth relative to user-supplied path
  515. * @param {Number} depth Child path actually targeted for watch
  516. * @param {String=} target Child path actually targeted for watch
  517. * @returns {Promise}
  518. */
  519. async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
  520. const ready = this.fsw._emitReady;
  521. if (this.fsw._isIgnored(path) || this.fsw.closed) {
  522. ready();
  523. return false;
  524. }
  525. const wh = this.fsw._getWatchHelpers(path, depth);
  526. if (!wh.hasGlob && priorWh) {
  527. wh.hasGlob = priorWh.hasGlob;
  528. wh.globFilter = priorWh.globFilter;
  529. wh.filterPath = entry => priorWh.filterPath(entry);
  530. wh.filterDir = entry => priorWh.filterDir(entry);
  531. }
  532. // evaluate what is at the path we're being asked to watch
  533. try {
  534. const stats = await statMethods[wh.statMethod](wh.watchPath);
  535. if (this.fsw.closed) return;
  536. if (this.fsw._isIgnored(wh.watchPath, stats)) {
  537. ready();
  538. return false;
  539. }
  540. const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START);
  541. let closer;
  542. if (stats.isDirectory()) {
  543. const absPath = sysPath.resolve(path);
  544. const targetPath = follow ? await fsrealpath(path) : path;
  545. if (this.fsw.closed) return;
  546. closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
  547. if (this.fsw.closed) return;
  548. // preserve this symlink's target path
  549. if (absPath !== targetPath && targetPath !== undefined) {
  550. this.fsw._symlinkPaths.set(absPath, targetPath);
  551. }
  552. } else if (stats.isSymbolicLink()) {
  553. const targetPath = follow ? await fsrealpath(path) : path;
  554. if (this.fsw.closed) return;
  555. const parent = sysPath.dirname(wh.watchPath);
  556. this.fsw._getWatchedDir(parent).add(wh.watchPath);
  557. this.fsw._emit(EV_ADD, wh.watchPath, stats);
  558. closer = await this._handleDir(parent, stats, initialAdd, depth, path, wh, targetPath);
  559. if (this.fsw.closed) return;
  560. // preserve this symlink's target path
  561. if (targetPath !== undefined) {
  562. this.fsw._symlinkPaths.set(sysPath.resolve(path), targetPath);
  563. }
  564. } else {
  565. closer = this._handleFile(wh.watchPath, stats, initialAdd);
  566. }
  567. ready();
  568. this.fsw._addPathCloser(path, closer);
  569. return false;
  570. } catch (error) {
  571. if (this.fsw._handleError(error)) {
  572. ready();
  573. return path;
  574. }
  575. }
  576. }
  577. }
  578. module.exports = NodeFsHandler;