mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 22:23:33 +01:00
AbsolutePaths: makeAbsolute() computes an absolute path from a relative one
The base is assumed to be exports.findEtherpadRoot(), without depending on process.cwd.
This commit is contained in:
parent
1b938a7a40
commit
5406472d65
1 changed files with 21 additions and 0 deletions
|
@ -114,3 +114,24 @@ exports.findEtherpadRoot = function() {
|
|||
absPathLogger.error(`To run, Etherpad has to identify an absolute base path. This is not: "${etherpadRoot}"`);
|
||||
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 a new issue