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') var config = require('./config.js')
, fs = require('fs') , fs = require('fs')
, Tail = require('tail').Tail , tail = require('tailfd').tail
// watcher on build_status // watcher on build_status
function __watch_build_status (socket, status) { function __watch_build_status (socket, status) {
status_watcher = new Tail(config.debomatic.jsonfile) tail(config.debomatic.jsonfile, function(new_content) {
status_watcher.on('line', function(new_content) {
var data = null var data = null
try { try {
data = JSON.parse(new_content) data = JSON.parse(new_content)
......
var path = require('path') var path = require('path')
, fs = require('fs') , fs = require('fs')
, Tail = require('tail').Tail , tail = require('tailfd').tail
, config = require('./config.js') , config = require('./config.js')
function __errors_handler(from, err, socket) { function __errors_handler(from, err, socket) {
...@@ -75,13 +75,9 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) { ...@@ -75,13 +75,9 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
name = "watcher-" + event_name name = "watcher-" + event_name
socket.get(name, function (err, watcher) { socket.get(name, function (err, watcher) {
try { try {
if (watcher) { if (watcher)
try { watcher.close()
watcher.unwatch()
} catch (errorWatchingDirectory) {
watcher.close()
}
}
fs.stat(watch_path, function(err, stats) { fs.stat(watch_path, function(err, stats) {
if (err) { if (err) {
utils.errors_handler("__watch_path_onsocket:fs.stat", err, socket) 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) { ...@@ -94,17 +90,12 @@ function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
}) })
} }
else { else {
watcher = new Tail(watch_path) watcher = tail(watch_path,function(line, tailInfo) {
watcher.on('line', function(new_content) {
data.file.new_content = new_content + '\n' data.file.new_content = new_content + '\n'
updater(event_name, socket, data) 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) { } catch (err) {
__errors_handler("__watch_path_onsocket <- " + arguments.callee.caller.name, err, socket) __errors_handler("__watch_path_onsocket <- " + arguments.callee.caller.name, err, socket)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
, "ejs": ">= 0.0.1" , "ejs": ">= 0.0.1"
, "socket.io": "*" , "socket.io": "*"
, "node-fs": "*" , "node-fs": "*"
, "tail": "*" , "tailfd": "*"
} }
, "scripts": { , "scripts": {
"install": "bash scripts/install.sh" "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