changeset 14057:312542dd184d 13.0

prosody: Fix loading local code when also installed system-wide loader.lua is responsible for adjusting the Lua module loading behavior to account for legacy code (mostly community modules) that don't load resources with the 'prosody' namespace prefix, like `require"prosody.util.json"` rather than `require"util.json"`, as well as the opposite problem of finding resources with the namespace prefix in a local source directory, where Lua would look for `./prosody/util/json.lua` instead of `./util/json.lua`. Which of these two behaviors is active depends on whether the loader is loaded as `require"prosody.loader"` or `require"loader"`, the former being intended for system-wide installations and the later for running from source. When you have a system-wide Prosody installed to the standard Lua search paths, the first attempt to require "prosody.loader" would succeed, leading to system-wide resources being preferred. This makes it difficult to run Prosody from source, e.g. a different version or with local patches, as those changes would be ignored. This change should make it more likely that the loader is invoked as just "loader" instead of "prosody.loader", which determines
author Kim Alvefur <zash@zash.se>
date Sun, 01 Feb 2026 15:22:53 +0100
parents 5b4efb5b798a
children f20b3f0d892b 2bdddcfad61d
files prosody prosodyctl
diffstat 2 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/prosody	Sun Feb 01 15:21:40 2026 +0100
+++ b/prosody	Sun Feb 01 15:22:53 2026 +0100
@@ -27,6 +27,7 @@
 
 -- Tell Lua where to find our libraries
 if CFG_SOURCEDIR then
+	-- Installed instance
 	local function is_relative(path)
 		local path_sep = package.config:sub(1,1);
 		return ((path_sep == "/" and path:sub(1,1) ~= "/")
@@ -40,6 +41,11 @@
 	end
 	package.path = sanitise_paths(CFG_SOURCEDIR.."/?.lua;"..package.path);
 	package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath);
+
+	require "prosody.loader";
+else
+	-- Not installed, e.g. running from a source checkout
+	require "loader";
 end
 
 -- Substitute ~ with path to home directory in data path
@@ -50,10 +56,6 @@
 end
 
 
-if not pcall(require, "prosody.loader") then
-	pcall(require, "loader");
-end
-
 local startup = require "prosody.util.startup";
 local async = require "prosody.util.async";
 
--- a/prosodyctl	Sun Feb 01 15:21:40 2026 +0100
+++ b/prosodyctl	Sun Feb 01 15:22:53 2026 +0100
@@ -27,6 +27,7 @@
 
 -- Tell Lua where to find our libraries
 if CFG_SOURCEDIR then
+	-- Installed instance
 	local function is_relative(path)
 		local path_sep = package.config:sub(1,1);
 		return ((path_sep == "/" and path:sub(1,1) ~= "/")
@@ -40,6 +41,11 @@
 	end
 	package.path = sanitise_paths(CFG_SOURCEDIR.."/?.lua;"..package.path);
 	package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath);
+
+	require "prosody.loader";
+else
+	-- Not installed, e.g. running from a source checkout
+	require "loader";
 end
 
 -- Substitute ~ with path to home directory in data path
@@ -50,10 +56,6 @@
 end
 
 
-if not pcall(require, "prosody.loader") then
-	pcall(require, "loader");
-end
-
 local startup = require "prosody.util.startup";
 startup.prosodyctl();