Throws errors when filesystem changes during Hound.prototype.watch
cspotcode opened this issue · 3 comments
If a file is created and then deleted before Hound.prototype.watch
has a chance to execute, then Hound will attempt to stat a non-existent file. All other fs operations run by Hound can also fail under similar circumstances.
I was able to throw in some try-catches to fix the problem but a proper solution depends on what kind of guarantees you want to make about Hound's behavior.
If Hound must report all FS changes, however temporary, then you've got a problem. If a file is created and then deleted before Hound can stat the file, it'll have to fire a 'create'
event without any stat data, followed by a 'delete'
event.
It's easier if you only require Hound to fire enough events that an observer arrives at a valid view of the eventual steady-state of the filesystem. In other words, if a file is created and then immediately deleted, Hound doesn't need to fire any events. "oops, it was too fast." Of course, if a file is created and remains extant then Hound is required to fire a 'created'
event. If the file is modified twice in quick succession, Hound can get away with firing only one 'change'
event, provided that event fires after the second file change has completed. For my personal use-case (automatically rebuilding templates & recompiling code as I edit them) this is totally fine.
Hi @cspotcode, sorry about the delay getting back to you, I'll look at this one this week.
Any updates on this?
I, too, managed to work around it with a couple of try/catch blocks--one around the body of the watch method, and one around the create event on hound.js:70.
I needed those because fs was throwing errors when WebStorm would very rapidly create and delete temporary files with ___jb_bak___
and ___jb_old___
suffixes, which it couldn't catch in time. I was using it to watch a directory.