From: Steinar H. Gunderson Date: Sat, 6 Sep 2014 04:20:23 +0000 (+0200) Subject: Fix an issue in the node.js sender where it would not catch the renames from remotegl... X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=5426efdc76c6a78aceb84ab8b3de262ccb3cfdf3;ds=sidebyside Fix an issue in the node.js sender where it would not catch the renames from remoteglot.pl. --- diff --git a/www/serve-analysis.js b/www/serve-analysis.js index 56845ee..5b08484 100644 --- a/www/serve-analysis.js +++ b/www/serve-analysis.js @@ -6,6 +6,7 @@ var http = require('http'); var fs = require('fs'); var url = require('url'); var querystring = require('querystring'); +var path = require('path'); // Constants. var json_filename = '/srv/analysis.sesse.net/www/analysis.json'; @@ -24,7 +25,11 @@ var request_id = 0; // Used to show a viewer count to the user. var last_seen_clients = {}; -var reread_file = function() { +var reread_file = function(event, filename) { + if (filename != path.basename(json_filename)) { + return; + } + console.log("Rereading " + json_filename); fs.open(json_filename, 'r+', function(err, fd) { if (err) throw err; fs.fstat(fd, function(err, st) { @@ -89,7 +94,7 @@ var count_viewers = function() { // Set up a watcher to catch changes to the file, then do an initial read // to make sure we have a copy. -fs.watch(json_filename, reread_file); +fs.watch(path.dirname(json_filename), reread_file); reread_file(); http.createServer(function(request, response) {