Catch more errors in file watcher node.

This commit is contained in:
Dave C-J 2014-05-31 19:44:02 +01:00
parent a4d27e4cb5
commit 8c8f75df69
2 changed files with 11 additions and 4 deletions

View File

@ -16,11 +16,11 @@
<script type="text/x-red" data-template-name="watch">
<div class="form-row node-input-filename">
<label for="node-input-files"><i class="icon-file"></i> File(s)</label>
<label for="node-input-files"><i class="fa fa-file"></i> File(s)</label>
<input type="text" id="node-input-files" placeholder="File(s) or Directory">
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div id="node-input-tip" class="form-tips">On Windows you must use double slashes \\ in any directory names.</div>

View File

@ -29,13 +29,20 @@ module.exports = function(RED) {
}
this.p = (this.files.length == 1) ? this.files[0] : JSON.stringify(this.files);
var node = this;
var notifications = new notify(node.files);
notifications.on('change', function (file, event, path) {
if (fs.statSync(path).isDirectory()) { path = path + sep + file; }
var msg = { payload: path, topic: node.p, file: file};
try {
if (fs.statSync(path).isDirectory()) { path = path + sep + file; }
} catch(e) { }
var msg = { payload: path, topic: node.p, file: file };
node.send(msg);
});
notifications.on('error', function (error, path) {
node.warn(error);
});
this.close = function() {
notifications.close();
}