Comparison

util/startup.lua @ 10194:dad1bc5fdb8e

util.startup: Removed/rewrote comments at setup_plugindir
author João Duarte <jvsDuarte08@gmail.com>
date Thu, 01 Aug 2019 08:02:26 -0700
parent 10193:9cad58759b3e
child 10195:3409f746f978
comparison
equal deleted inserted replaced
10193:9cad58759b3e 10194:dad1bc5fdb8e
226 end 226 end
227 227
228 function startup.setup_plugindir() 228 function startup.setup_plugindir()
229 local custom_plugin_paths = config.get("*", "plugin_paths"); 229 local custom_plugin_paths = config.get("*", "plugin_paths");
230 local installer_plugin_path = config.get("*", "installer_plugin_path") or "custom_plugins"; 230 local installer_plugin_path = config.get("*", "installer_plugin_path") or "custom_plugins";
231 -- This variable separates different paths, like this "," here -> /usr;/home
232 local path_sep = package.config:sub(3,3); 231 local path_sep = package.config:sub(3,3);
233 -- This variable is the separator between directories, in a path, like the "/" here -> /home/path/to/somewhere
234 local dir_sep = package.config:sub(1,1); 232 local dir_sep = package.config:sub(1,1);
235 if custom_plugin_paths then 233 if custom_plugin_paths then
236 -- path1;path2;path3;defaultpath... 234 -- path1;path2;path3;defaultpath...
237 -- luacheck: ignore 111 235 -- luacheck: ignore 111
238 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins"); 236 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins");
239 prosody.paths.plugins = CFG_PLUGINDIR; 237 prosody.paths.plugins = CFG_PLUGINDIR;
240 end 238 end
241 local current_directory = require "lfs".currentdir(); 239 local current_directory = require "lfs".currentdir();
242 installer_plugin_path = config.resolve_relative_path(current_directory, installer_plugin_path); 240 installer_plugin_path = config.resolve_relative_path(current_directory, installer_plugin_path);
243 require "lfs".mkdir(installer_plugin_path) 241 require "lfs".mkdir(installer_plugin_path)
244 -- Developers may have add these custom paths to their LUA_PATH/LUA_CPATH variables, before running prosody 242 -- Checking for duplicates
245 -- Therefore, I'll just check if the paths we are about to add aren't already at package.(path/cpath) 243 -- The commands using luarocks need the path to the directory that has the /share and /lib folders.
246 if not string.match(package.path, installer_plugin_path) then 244 if not string.match(package.path, installer_plugin_path) then
247 local lua_version = _VERSION:match(" (.+)$") 245 local lua_version = _VERSION:match(" (.+)$")
248 -- I'm assuming there's good reason not to hard code any separator
249 -- This next line is unnecessary, but I think it makes the code more readable and neat
250 local sub_path = dir_sep.."lua"..dir_sep..lua_version..dir_sep 246 local sub_path = dir_sep.."lua"..dir_sep..lua_version..dir_sep
251 package.path = package.path..path_sep..installer_plugin_path..dir_sep.."share"..sub_path.."?.lua"; 247 package.path = package.path..path_sep..installer_plugin_path..dir_sep.."share"..sub_path.."?.lua";
252 package.path = package.path..path_sep..installer_plugin_path..dir_sep.."share"..sub_path.."?"..dir_sep.."init.lua"; 248 package.path = package.path..path_sep..installer_plugin_path..dir_sep.."share"..sub_path.."?"..dir_sep.."init.lua";
253 package.cpath = package.cpath..path_sep..installer_plugin_path..dir_sep.."lib"..sub_path.."?.lua"; 249 package.cpath = package.cpath..path_sep..installer_plugin_path..dir_sep.."lib"..sub_path.."?.lua";
254 end 250 end
255 -- The commands using luarocks need the path to the directory that has the /share and /lib folders.
256 CFG_PLUGINDIR = installer_plugin_path..path_sep..(CFG_PLUGINDIR or "plugins"); 251 CFG_PLUGINDIR = installer_plugin_path..path_sep..(CFG_PLUGINDIR or "plugins");
257 prosody.paths.plugins = CFG_PLUGINDIR; 252 prosody.paths.plugins = CFG_PLUGINDIR;
258 end 253 end
259 254
260 function startup.chdir() 255 function startup.chdir()