aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorJoão Duarte <jvsDuarte08@gmail.com>2019-07-26 17:54:37 -0700
committerJoão Duarte <jvsDuarte08@gmail.com>2019-07-26 17:54:37 -0700
commitad26c41fa6a4ac22d08b62dbadd13e49156ed305 (patch)
tree5dbab3d1a3afc1aa102230205ce48b98b3bd0894 /util
parent093110478e9ad8bbc539a10b07ce968387255a74 (diff)
downloadprosody-ad26c41fa6a4ac22d08b62dbadd13e49156ed305.tar.gz
prosody-ad26c41fa6a4ac22d08b62dbadd13e49156ed305.zip
util.startup: Improved how .set_plugindir updates prosody.paths.plugins, package.path and package.cpath
Diffstat (limited to 'util')
-rw-r--r--util/startup.lua38
1 files changed, 27 insertions, 11 deletions
diff --git a/util/startup.lua b/util/startup.lua
index 9ddb10b5..4601bd85 100644
--- a/util/startup.lua
+++ b/util/startup.lua
@@ -226,28 +226,44 @@ function startup.setup_datadir()
end
function startup.setup_plugindir()
- --local lfs_currentdir = require "lfs".currentdir()
- --local current_directory = lfs_currentdir
local custom_plugin_paths = config.get("*", "plugin_paths");
local installer_plugin_path = config.get("*", "installer_plugin_path") or "custom_plugins";
+ -- This variable separates different paths, like this "," here -> /usr;/home
local path_sep = package.config:sub(3,3);
+ -- This variable is the separator between directories, in a path, like the "/" here -> /home/path/to/somewhere
+ local dir_sep = package.config:sub(1,1);
if custom_plugin_paths then
-- path1;path2;path3;defaultpath...
-- luacheck: ignore 111
CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins");
prosody.paths.plugins = CFG_PLUGINDIR;
end
- -- Checking if the folder exists. If it doesn't, we create it
+ -- Checks if installer_plugin_path is a relative paths and makes it an absolute path
+ if installer_plugin_path:sub(1,1) ~= "/" then
+ -- Works fine when executing prosody from source (configure and make only)
+ -- Probably wont be the best install directory, when using a package installation
+ local lfs_currentdir = require "lfs".currentdir();
+ local current_directory = lfs_currentdir;
+ -- Some normalization
+ installer_plugin_path = installer_plugin_path:gsub("^%.%"..dir_sep.."+", "");
+ installer_plugin_path = current_directory..dir_sep..installer_plugin_path;
+ end
+ -- Checking if the folder exists. If it doesn't, we create it, but we need permissions to do so
if os.execute('[ -d "'..installer_plugin_path..'" ]') ~= 0 then
- os.execute("mkdir "..installer_plugin_path)
+ os.execute("mkdir "..installer_plugin_path);
+ end
+ -- Developers may have add these custom paths to their LUA_PATH/LUA_CPATH variables, before running prosody
+ -- Therefore, I'll just check if the paths we are about to add aren't already at package.(path/cpath)
+ if not string.match(package.path, installer_plugin_path) then
+ local lua_version = _VERSION:match(" (.+)$")
+ -- I'm assuming there's good reason not to hard code any separator
+ -- This next line is unnecessary, but I think it makes the code more readable and neat
+ local sub_path = dir_sep.."lua"..dir_sep..lua_version..dir_sep
+ package.path = package.path..path_sep..installer_plugin_path..dir_sep.."share"..sub_path.."?.lua";
+ package.path = package.path..path_sep..installer_plugin_path..dir_sep.."share"..sub_path.."?"..dir_sep.."init.lua";
+ package.cpath = package.cpath..path_sep..installer_plugin_path..dir_sep.."lib"..sub_path.."?.lua";
end
- --[[if not string.find(package.path, current_directory..installer_plugin_path[path]) then
- --os.execute("ls -la "..current_directory..path_sep..installer_plugin_paths[path])
- package.path = package.path..path_sep..current_directory..installer_plugin_path.."/?.lua"..path_sep..path_sep
- package.path = package.path..current_directory..installer_plugin_path.."/?/init.lua"..path_sep..path_sep
- package.cpath = package.cpath..path_sep..current_directory..installer_plugin_path.."/?.lua"
- package.cpath = package.cpath..path_sep..current_directory..installer_plugin_path.."/?/init.lua"
- end]]
+ -- The commands using luarocks need the path to the directory that has the /share and /lib folders.
CFG_PLUGINDIR = installer_plugin_path..path_sep..(CFG_PLUGINDIR or "plugins");
prosody.paths.plugins = CFG_PLUGINDIR;
end