From d0f093413cbaff28d96ea0cc2c29101586ff4a71 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 3 Oct 2016 22:19:13 -0400 Subject: [PATCH] Use optimisticStatOrNull in tools/fs/watch.js. --- tools/fs/watch.js | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/tools/fs/watch.js b/tools/fs/watch.js index 8624112402..348178e0a0 100644 --- a/tools/fs/watch.js +++ b/tools/fs/watch.js @@ -6,6 +6,7 @@ import {coalesce} from '../utils/func-utils.js'; import {Profile} from '../tool-env/profile.js'; import { + optimisticStatOrNull, optimisticReaddir, optimisticHashOrNull, } from "./optimistic.js"; @@ -279,22 +280,19 @@ export function readDirectory({absPath, include, exclude, names}) { // Add slashes to the end of directories. var contentsWithSlashes = []; _.each(contents, function (entry) { - try { - // We do stat instead of lstat here, so that we treat symlinks to - // directories just like directories themselves. - // XXX Does the treatment of symlinks make sense? - var stats = files.stat(files.pathJoin(absPath, entry)); - } catch (e) { - if (e && (e.code === 'ENOENT')) { - // Disappeared after the readdir (or a dangling symlink)? Eh, - // pretend it was never there in the first place. - return; - } - throw e; + // We do stat instead of lstat here, so that we treat symlinks to + // directories just like directories themselves. + const stat = optimisticStatOrNull(files.pathJoin(absPath, entry)); + if (! stat) { + // Disappeared after the readdir (or a dangling symlink)? + // Eh, pretend it was never there in the first place. + return; } - if (stats.isDirectory()) { + + if (stat.isDirectory()) { entry += '/'; } + contentsWithSlashes.push(entry); }); @@ -592,16 +590,7 @@ export class Watcher { var self = this; var entry = self.watches[absPath]; var lastStat = entry.lastStat; - - try { - var stat = files.stat(absPath); - } catch (err) { - stat = null; - if (err.code !== "ENOENT") { - throw err; - } - } - + var stat = optimisticStatOrNull(absPath); var mustNotExist = self._mustNotExist(absPath); var mustBeAFile = self._mustBeAFile(absPath);