From ac545ccc5286607d23840817269ea90ec53ba68b Mon Sep 17 00:00:00 2001 From: Praneeth Bodduluri <praneeth@bufferlabs.in> Date: Fri, 28 Aug 2015 01:49:20 +0530 Subject: [PATCH] Change the EEXIST to a function --- src/utils.coffee | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils.coffee b/src/utils.coffee index f0c02bb0..24c0b970 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -6,7 +6,6 @@ mixpanel = require 'mixpanel' networkCheck = require 'network-checker' blink = require('blinking')(config.ledFile) url = require 'url' -fs = Promise.promisifyAll require 'fs' utils = exports @@ -97,14 +96,16 @@ vpnStatusInotifyCallback = -> .catch -> pauseConnectivityCheck = false +# Use the following to catch EEXIST errors +EEXIST = (err) -> err.code is 'EEXIST' + exports.connectivityCheck = _.once -> parsedUrl = url.parse(config.apiEndpoint) fs.mkdirAsync(config.vpnStatusPath) .then -> fs.watch(config.vpnStatusPath, vpnStatusInotifyCallback) - .catch (error) -> - if error.code != 'EEXIST' - throw error + .catch EEXIST, (err) -> + # Manually trigger the call back to detect cases when VPN was switched on before the supervisor starts. vpnStatusInotifyCallback() customMonitor