Fix watch node to stat file sizes ok

(and also not to when file missing)
This commit is contained in:
dceejay 2015-04-08 21:43:22 +01:00
parent e1f0969957
commit be1620dd07
1 changed files with 12 additions and 9 deletions

View File

@ -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);
});