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
parent
1b938a7a40
commit
5406472d65
|
@ -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;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue