Commit b8100440 authored by Leo Iannacone's avatar Leo Iannacone

Tail module is a bit bugged if file watched is removed.

Use tailfd instead.
parent 3d3ed940
var config = require('./config.js')
, fs = require('fs')
, Tail = require('tail').Tail
, tail = require('tailfd').tail
// watcher on build_status
function __watch_build_status (socket, status) {
status_watcher = new Tail(config.debomatic.jsonfile)
status_watcher.on('line', function(new_content) {
tail(config.debomatic.jsonfile, function(new_content) {
var data = null
try {
data = JSON.parse(new_content)
......
var path = require('path')
, fs = require('fs')
, Tail = require('tail').Tail
, tail = require('tailfd').tail
, config = require('./config.js')
function __errors_handler(from, err, socket) {
......@@ -75,13 +75,9 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
name = "watcher-" + event_name
socket.get(name, function (err, watcher) {
try {
if (watcher) {
try {
watcher.unwatch()
} catch (errorWatchingDirectory) {
watcher.close()
}
}
if (watcher)
watcher.close()
fs.stat(watch_path, function(err, stats) {
if (err) {
utils.errors_handler("__watch_path_onsocket:fs.stat", err, socket)
......@@ -94,17 +90,12 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
})
}
else {
watcher = new Tail(watch_path)
watcher.on('line', function(new_content) {
watcher = tail(watch_path,function(line, tailInfo) {
data.file.new_content = new_content + '\n'
updater(event_name, socket, data)
}).on('error', function(err) {
watcher.unwatch()
__errors_handler("__watch_path_onsocket.Tail <- " + arguments.callee.caller.name, err, socket)
return
})
socket.set(name, watcher)
});
}
socket.set(name, watcher)
})
} catch (err) {
__errors_handler("__watch_path_onsocket <- " + arguments.callee.caller.name, err, socket)
......
......@@ -7,7 +7,7 @@
, "ejs": ">= 0.0.1"
, "socket.io": "*"
, "node-fs": "*"
, "tail": "*"
, "tailfd": "*"
}
, "scripts": {
"install": "bash scripts/install.sh"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment