From 631b23f7a252c25f46bbb1e2e640eadd6843ffad Mon Sep 17 00:00:00 2001 From: muxator Date: Mon, 11 Feb 2019 00:02:55 +0100 Subject: [PATCH] utils/AbsolutePaths.js: do not break when running as a Windows manual install A Windows manual install has the same directory layout of a normal Unix one (e.g. the nice symlink node_modules/ep_etherpad-lite -> ../src). Only when running from the pre-built Windows package the directory layout is different (e.g. src is physically copied into node_modules/ep_etherpad-lite). The previous version of the code wrongly assumed that all Windows installs would be run from the pre-built pakage. In this version the path search is the same on all platform. If it fails, and we are on Windows, there is a fallback for the specific case of the pre-built package. Fixes #3550 --- src/node/utils/AbsolutePaths.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/node/utils/AbsolutePaths.js b/src/node/utils/AbsolutePaths.js index 55dfc98e..9d864c47 100644 --- a/src/node/utils/AbsolutePaths.js +++ b/src/node/utils/AbsolutePaths.js @@ -61,8 +61,8 @@ var popIfEndsWith = function(stringArray, lastDesiredElements) { * Heuristically computes the directory in which Etherpad is installed. * * All the relative paths have to be interpreted against this absolute base - * path. Since the Unix and Windows install have a different layout on disk, - * they are treated as two special cases. + * path. Since the Windows package install has a different layout on disk, it is + * dealt with as a special case. * * The path is computed only on first invocation. Subsequent invocations return * a cached value. @@ -79,26 +79,27 @@ exports.findEtherpadRoot = function() { const findRoot = require('find-root'); const foundRoot = findRoot(__dirname); + const splitFoundRoot = foundRoot.split(path.sep); - var directoriesToStrip; - if (process.platform === 'win32') { + /* + * On Unix platforms and on Windows manual installs, foundRoot's value will + * be: + * + * \src + */ + var maybeEtherpadRoot = popIfEndsWith(splitFoundRoot, ['src']); + + if ((maybeEtherpadRoot === false) && (process.platform === 'win32')) { /* - * Given the structure of our Windows package, foundRoot's value - * will be the following on win32: + * If we did not find the path we are expecting, and we are running under + * Windows, we may still be running from a prebuilt package, whose directory + * structure is different: * * \node_modules\ep_etherpad-lite */ - directoriesToStrip = ['node_modules', 'ep_etherpad-lite']; - } else { - /* - * On Unix platforms, foundRoot's value will be: - * - * \src - */ - directoriesToStrip = ['src']; + maybeEtherpadRoot = popIfEndsWith(splitFoundRoot, ['node_modules', 'ep_etherpad-lite']); } - const maybeEtherpadRoot = popIfEndsWith(foundRoot.split(path.sep), directoriesToStrip); if (maybeEtherpadRoot === false) { absPathLogger.error(`Could not identity Etherpad base path in this ${process.platform} installation in "${foundRoot}"`); process.exit(1);