From be1620dd07a579f8e1351bb019c0749f03c22f0f Mon Sep 17 00:00:00 2001 From: dceejay Date: Wed, 8 Apr 2015 21:43:22 +0100 Subject: [PATCH] Fix watch node to stat file sizes ok (and also not to when file missing) --- nodes/core/io/23-watch.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/nodes/core/io/23-watch.js b/nodes/core/io/23-watch.js index 59cd57069..400b7f1bd 100644 --- a/nodes/core/io/23-watch.js +++ b/nodes/core/io/23-watch.js @@ -37,15 +37,18 @@ module.exports = function(RED) { if (fs.statSync(path).isDirectory()) { path = path + sep + file; } stat = fs.statSync(path); } catch(e) { } - var type = "other"; - if (stat.isFile()) { type = "file"; } - else if (stat.isDirectory()) { type = "directory"; } - else if (stat.isBlockDevice()) { type = "blockdevice"; } - else if (stat.isCharacterDevice()) { type = "characterdevice"; } - else if (stat.isSocket()) { type = "socket"; } - else if (stat.isFIFO()) { type = "fifo"; } - else { type = "n/a"; } - var msg = { payload:path, topic:node.p, file:file, type:type, size:stat.size }; + var type = "none"; + var msg = { payload:path, topic:node.p, file:file }; + if (stat) { + if (stat.isFile()) { type = "file"; msg.size = stat.size; } + else if (stat.isDirectory()) { type = "directory"; } + else if (stat.isBlockDevice()) { type = "blockdevice"; } + else if (stat.isCharacterDevice()) { type = "characterdevice"; } + else if (stat.isSocket()) { type = "socket"; } + else if (stat.isFIFO()) { type = "fifo"; } + else { type = "n/a"; } + } + msg.type = type; node.send(msg); });