AbsolutePaths: makeAbsolute() computes an absolute path from a relative one

The base is assumed to be exports.findEtherpadRoot(), without depending on
process.cwd.
pull/3473/head
muxator 2018-08-22 01:14:30 +02:00 committed by muxator
parent 1b938a7a40
commit 5406472d65
1 changed files with 21 additions and 0 deletions

View File

@ -114,3 +114,24 @@ exports.findEtherpadRoot = function() {
absPathLogger.error(`To run, Etherpad has to identify an absolute base path. This is not: "${etherpadRoot}"`); absPathLogger.error(`To run, Etherpad has to identify an absolute base path. This is not: "${etherpadRoot}"`);
process.exit(1); process.exit(1);
}; };
/**
* Receives a filesystem path in input. If the path is absolute, returns it
* unchanged. If the path is relative, an absolute version of it is returned,
* built prepending exports.findEtherpadRoot() to it.
*
* @param {string} somePath - an absolute or relative path
* @return {string} An absolute path. If the input path was already absolute,
* it is returned unchanged. Otherwise it is interpreted
* relative to exports.root.
*/
exports.makeAbsolute = function(somePath) {
if (path.isAbsolute(somePath)) {
return somePath;
}
const rewrittenPath = path.normalize(path.join(exports.findEtherpadRoot(), somePath));
absPathLogger.debug(`Relative path "${somePath}" can be rewritten to "${rewrittenPath}"`);
return rewrittenPath;
};