Changeset

10390:82705ec87253 0.11

util.startup: Ensure prosody.paths are absolute (see #1430) Normally these paths are injected into the installed 'prosody' executable as absolute paths, but it is possible to override at least the config path via environment variable or command line argument. This makes sure a path relative to pwd stays relative to that instead of the data directory.
author Kim Alvefur <zash@zash.se>
date Mon, 04 Nov 2019 00:29:49 +0100
parents 10389:dbb8dae58265
children 10391:986349fc0f9e 10400:4c2d789a106b
files util/startup.lua
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/startup.lua	Sun Nov 03 22:19:09 2019 +0100
+++ b/util/startup.lua	Mon Nov 04 00:29:49 2019 +0100
@@ -231,8 +231,14 @@
 
 function startup.chdir()
 	if prosody.installed then
+		local lfs = require "lfs";
+		-- Ensure paths are absolute, not relative to the working directory which we're about to change
+		local cwd = lfs.currentdir();
+		prosody.paths.source = config.resolve_relative_path(cwd, prosody.paths.source);
+		prosody.paths.config = config.resolve_relative_path(cwd, prosody.paths.config);
+		prosody.paths.data = config.resolve_relative_path(cwd, prosody.paths.data);
 		-- Change working directory to data path.
-		require "lfs".chdir(prosody.paths.data);
+		lfs.chdir(prosody.paths.data);
 	end
 end