From 5426efdc76c6a78aceb84ab8b3de262ccb3cfdf3 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 6 Sep 2014 06:20:23 +0200 Subject: [PATCH] Fix an issue in the node.js sender where it would not catch the renames from remoteglot.pl. --- www/serve-analysis.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) { -- 2.39.2