# HG changeset patch # User Kim Alvefur # Date 1601925203 -7200 # Node ID 287d0d80aa5793c701b2506cf03266d4c7c44fdb # Parent 40abef01f4b9f99f4f73699de11d936a0a250df9 util.prosodyctl: Construct luarocks command line with templates More flexible and safer wrt escaping diff -r 40abef01f4b9 -r 287d0d80aa57 util/prosodyctl.lua --- a/util/prosodyctl.lua Mon Oct 05 20:58:37 2020 +0200 +++ b/util/prosodyctl.lua Mon Oct 05 21:13:23 2020 +0200 @@ -12,6 +12,7 @@ local stringprep = encodings.stringprep; local storagemanager = require "core.storagemanager"; local usermanager = require "core.usermanager"; +local interpolation = require "util.interpolation"; local signal = require "util.signal"; local set = require "util.set"; local lfs = require "lfs"; @@ -224,6 +225,8 @@ end end +local render_cli = interpolation.new("%b{}", function (s) return "'"..s:gsub("'","'\\''").."'" end) + local function call_luarocks(mod, operation) local dir = get_path_custom_plugins(prosody.paths.plugins); if operation == "install" then @@ -232,9 +235,11 @@ show_message("Removing %s from %s", mod, dir); end if operation == "list" then - os.execute("luarocks list --tree='"..dir.."'") + os.execute(render_cli("luarocks list --tree={dir}", {dir = dir})); else - os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); + os.execute(render_cli("luarocks {op} --tree={dir} {server&--server={server}} {mod}", { + dir = dir; op = operation; mod = mod; server = "http://localhost/"; + })); end if operation == "install" then show_module_configuration_help(mod);