From 38539ca80b5693b446671ba4c952af29dd270c88 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 14 Sep 2017 15:44:09 -0400 Subject: [PATCH] Account for absolute paths in configuration * bin/server.js: Resolve absolute paths as such. (_resolvePath): Add function. --- bin/server.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/server.js b/bin/server.js index e44688c..ec93fb7 100644 --- a/bin/server.js +++ b/bin/server.js @@ -52,8 +52,8 @@ ConfLoader( fs, ConfStore ) ] ) ) .then( ([ name, daemon, pidfile, conf ]) => { - const daemon_path = conf_dir + '/' + daemon; - const pid_path = conf_dir + '/' + ( pidfile || ".pid" ); + const daemon_path = _resolvePath( conf_dir, daemon ); + const pid_path = _resolvePath( conf_dir, ( pidfile || ".pid" ) ); writePidFile( pid_path ); greet( name, pid_path ); @@ -66,6 +66,23 @@ ConfLoader( fs, ConfStore ) } ); +/** + * Produce an absolute path if `path` is absolute, otherwise a path relative + * to the configuration directory + * + * @param {string} conf_path configuration path (for relative `path`) + * @param {string} path path to resolve + * + * @return resolved path + */ +function _resolvePath( conf_path, path ) +{ + return ( path[ 0 ] === '/' ) + ? path + : conf_path + '/' + path; +} + + function writePidFile( pid_path ) { fs.writeFile( pid_path, process.pid );