Commit a9c8118d authored by Leo Iannacone's avatar Leo Iannacone

fix close watcher on changing watch_path

parent e9ab5277
...@@ -43,11 +43,17 @@ app.get('/', routes.index); ...@@ -43,11 +43,17 @@ app.get('/', routes.index);
function watch_path_onsocket(event_name, socket, data, watch_path, updater) { 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) {
if (watcher) if (watcher) {
try {
watcher.unwatch()
} catch (errorWatchingDirectory) {
watcher.close() watcher.close()
}
}
try { try {
fs.stat(watch_path, function(err, stats) { fs.stat(watch_path, function(err, stats) {
watcher = null if (err)
return
if (stats.isDirectory()) { if (stats.isDirectory()) {
watcher = fs.watch(watch_path, {persistent: true}, function (event, fileName) { watcher = fs.watch(watch_path, {persistent: true}, function (event, fileName) {
if(event == 'rename') if(event == 'rename')
...@@ -61,8 +67,8 @@ function watch_path_onsocket(event_name, socket, data, watch_path, updater) { ...@@ -61,8 +67,8 @@ function watch_path_onsocket(event_name, socket, data, watch_path, updater) {
updater(socket, data) updater(socket, data)
}) })
} }
})
socket.set(name, watcher) socket.set(name, watcher)
})
} catch (err_watch) {} } catch (err_watch) {}
}) })
} }
......
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