Browse files

Avoid continue reloading due to atime changes

watchFile() will watch for any changes to the file, including
the file's meta-data, such as its atime. The atime is updated
whenever a file is opened. When the server is restarted, it
re-opens the script file, which updates the atime, which then
causes the watchFile() event to fire again.

This changes explicitly checks the mtime and ctime fields,
and only restarts the server if these differ (ignoring atime
changes).

Additionally, an nterval is specified in watchFile() so that
when inotify is not available checks occur every 0.5 seconds,
rather than every 5 seconds.
  • Loading branch information...
1 parent 22cf69d commit 1da36e5daa03418a3de36658b91474e2cc7180b8 @bennoleslie bennoleslie committed Jun 22, 2010
Showing with 6 additions and 4 deletions.
  1. +6 −4 d.js
View
10 d.js
@@ -34,10 +34,12 @@ playlist(intro, function(err, list) {
// Watch changes on any files of the playlist
list.forEach(function(file) {
- fs.watchFile(file, function(curr, prev) {
- say("playlist updated");
- stop(playing, intro);
- playing = play(intro);
+ fs.watchFile(file, {interval : 500}, function(curr, prev) {
+ if (curr.mtime.valueOf() != prev.mtime.valueOf() || curr.ctime.valueOf() != prev.ctime.valueOf()) {
+ say("playlist updated: " + file);
+ stop(playing, intro);
+ playing = play(intro);
+ }
});
});

0 comments on commit 1da36e5

Please sign in to comment.