Commit f0db670a authored by Leo Iannacone's avatar Leo Iannacone

import tail in utils and use coffescript to rewrite methods - wating for...

import tail in utils and use coffescript to rewrite methods - wating for https://github.com/lucagrulla/node-tail/issues/16 get closed
parent cf413f52
fs = require("fs") fs = require("fs")
config = require("./config") config = require("./config")
utils = require("./utils") utils = require("./utils")
Tail = require("./tail") Tail = utils.Tail
e = config.events.broadcast e = config.events.broadcast
_get_distributions = (callback) -> _get_distributions = (callback) ->
......
"use strict"
fs = require("fs")
Tail = require("tail").Tail
Tail::watchEvent = (e) ->
_this = this
if e is "change"
fs.stat @filename, (err, stats) ->
if err
_this.emit "error", err
return
_this.pos = stats.size if stats.size < _this.pos
if stats.size > _this.pos
_this.queue.push
start: _this.pos
end: stats.size
_this.pos = stats.size
_this.internalDispatcher.emit "next" if _this.queue.length is 1
else if e is "rename"
@unwatch()
_this.emit "error", "File " + @filename + " deleted."
return
Tail::close = ->
@unwatch()
return
module.exports = Tail
path = require("path") path = require("path")
fs = require("fs") fs = require("fs")
config = require("./config") config = require("./config")
Tail = require("./tail") Tail = require("tail").Tail
_check_no_backward = (backward_path) -> _check_no_backward = (backward_path) ->
if typeof backward_path is 'string' if typeof backward_path is 'string'
...@@ -104,6 +104,22 @@ errors_handler = (from, err, socket) -> ...@@ -104,6 +104,22 @@ errors_handler = (from, err, socket) ->
socket.emit config.events.error, err.message if socket socket.emit config.events.error, err.message if socket
return return
Tail::watchEvent = (e) ->
if e is 'change'
fs.stat @filename, (err, stats) =>
@emit 'error', err if err
@pos = stats.size if stats.size < @pos #scenario where texts is not appended but it's actually a w+
if stats.size > @pos
@queue.push({start: @pos, end: stats.size})
@pos = stats.size
@internalDispatcher.emit("next") if @queue.length is 1
else if e is 'rename'
@unwatch()
@emit "error", "File #{@filename} deleted"
Tail::close = ->
@unwatch()
return
module.exports.check_data_distribution = check_data_distribution module.exports.check_data_distribution = check_data_distribution
module.exports.check_data_package = check_data_package module.exports.check_data_package = check_data_package
...@@ -115,3 +131,4 @@ module.exports.get_files_list = get_files_list ...@@ -115,3 +131,4 @@ module.exports.get_files_list = get_files_list
module.exports.watch_path_onsocket = watch_path_onsocket module.exports.watch_path_onsocket = watch_path_onsocket
module.exports.errors_handler = errors_handler module.exports.errors_handler = errors_handler
module.exports.arrayEqual = arrayEqual module.exports.arrayEqual = arrayEqual
module.exports.Tail = Tail
...@@ -579,10 +579,10 @@ function Page_Distrubion(socket) { ...@@ -579,10 +579,10 @@ function Page_Distrubion(socket) {
set: function (socket_error) { set: function (socket_error) {
if ($('#error').is(':visible')) if ($('#error').is(':visible'))
return; return;
socket_error = socket_error.replace(/File (.*) deleted./, socket_error = socket_error.replace(/File (.*) deleted(.*)/,
'<b>File removed</b>&nbsp;&nbsp;$1'); '<b>File removed</b>&nbsp;&nbsp;<em>$1</em>');
socket_error = socket_error.replace(/ENOENT, [a-z]+ '(.*)'/, socket_error = socket_error.replace(/ENOENT, [a-z]+ '(.*)'/,
'<b>No such file or directory</b>&nbsp;&nbsp;$1'); '<b>No such file or directory</b>&nbsp;&nbsp;<em>$1</em>');
$('#error .message').html(socket_error); $('#error .message').html(socket_error);
error.view(); error.view();
}, },
......
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