From f64b77a66cffaa68611b5bd2c26de2dace6cef72 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Thu, 23 Feb 2017 15:00:26 +0100 Subject: [PATCH] switched fs.exists with fs.access in shepherd.js --- routes/shepherd.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/routes/shepherd.js b/routes/shepherd.js index 9fd3569..dc3cab5 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -479,15 +479,17 @@ shepherd.readDebugLog = function(fileLocation, lastNLines) { return new Promise( function(resolve, reject) { if (lastNLines) { - if (fs.existsSync(fileLocation)) { - console.log('reading ' + fileLocation); - - readLastLines - .read(fileLocation, lastNLines) - .then((lines) => resolve(lines)); - } else { - reject('file ' + fileLocation + ' doesn\'t exist!'); - } + fs.access(fileLocation, fs.constants.R_OK, function(err) { + if (err) { + console.log('error reading ' + fileLocation); + reject('readDebugLog error: ' + err); + } else { + console.log('reading ' + fileLocation); + readLastLines + .read(fileLocation, lastNLines) + .then((lines) => resolve(lines)); + } + }); } else { reject('readDebugLog error: lastNLines param is not provided!'); }