Skip to content

Instantly share code, notes, and snippets.

@dlmanning dlmanning/watch.js
Last active Dec 23, 2015

Embed
What would you like to do?
Possible regression between 0.10.16 and 0.10.17 related to libuv patch
Running watch.js on node 0.10.17 and OS X 10.8.5 gives the following when editing (in Sublime Text) and saving file in the same directory:
change : a.txt
rename : .subl319.tmp
change : a.txt
rename : .subl69d.tmp
etc...
Doing the same on 0.10.18 gives:
rename : .subl738.tmp
rename : .sublade.tmp
The same issue occurs between 0.11.6 and 0.11.7. Based on the commit log I think it's related to the following change in libuv:
https://github.com/joyent/libuv/commit/9bae606d413327187828155b61babcd52b2d2517
var fs = require('fs');
fs.watch(__dirname, function (evt, filename) {
console.log(evt + ' : ' + filename);
})
@airportyh

This comment has been minimized.

Copy link

commented Sep 21, 2013

Thanks! I just tested on my Mac 10.7.5 and got a slightly different result

$ node -v
v0.10.18

$ node watch.js
rename : a.txt
rename : a.txt
rename : a.txt

$ node -v
v0.10.17

$ node watch.js
rename : a.txt
rename : a.txt
change : a.txt
change : a.txt

What version of Sublime Text do you have? Because I am not getting the strangly named tmp files.

@dlmanning

This comment has been minimized.

Copy link
Owner Author

commented Oct 19, 2013

Toby,

Sorry I didn't see your response before. I'm using Sublime Text 3. It looks like ST2 writes the files to the same location rather than saving to a temp and moving. vim does the same thing as ST3, though, so I don't understand how no one's noticed this.

Anyway, fireworm is continuing to work with ST2 because you're checking the filename associated with the event.

I'm pretty sure FSWatcher should be emitting a change event for the original filename along with the rename event in any case.

@jarofghosts

This comment has been minimized.

Copy link

commented Oct 19, 2013

For posterity, it seems to me that any change that occurs within ~200ms of another does not get emitted.. writing a test.

@dlmanning

This comment has been minimized.

Copy link
Owner Author

commented Oct 19, 2013

@dlmanning

This comment has been minimized.

Copy link
Owner Author

commented Oct 20, 2013

Turns out this was "fixed" when libuv 0.10.18 was rolled into node 0.10.21

joyent/libuv@38df93c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.