shama / gaze

:crystal_ball: A globbing fs.watch wrapper built from the best parts of other fine watch libs.
MIT License
1.16k stars 167 forks source link

Don't call fs.existsSync and then immediately call fs.lstatSync #232

Open rcombs opened 7 years ago

rcombs commented 7 years ago

See: https://github.com/shama/gaze/blob/master/lib/gaze.js#L388 existsSync makes a stat syscall, and then lstatSync makes an lstat syscall. This is redundant and a waste of time. Just call fs.lstatSync and handle the exception if the file doesn't exist. This also solves your race condition between the two calls, which currently results in an exception being thrown out of the map call.