mirror of
https://github.com/vxcontrol/soldr-modules.git
synced 2026-07-18 18:44:30 -04:00
auditd: pkg.Manager supports alternative names in install()
This commit is contained in:
@@ -14,13 +14,13 @@ describe("exec", function()
|
||||
local ok, err = exec("echo ERROR; false")
|
||||
assert(not ok)
|
||||
assert(string_contains(err, 'exit=1: ERROR'),
|
||||
"unexpected error message: "..tostring(err))
|
||||
string.format("unexpected error message: %s", err))
|
||||
end)
|
||||
|
||||
test("a bad command", function()
|
||||
local ok, err = exec("unknown-command")
|
||||
assert(not ok)
|
||||
assert(string_contains(err, "not found"),
|
||||
"unexpected error message: "..tostring(err))
|
||||
string.format("unexpected error message: %s", err))
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -47,11 +47,17 @@ function Manager:sync()
|
||||
end
|
||||
|
||||
-- Performs installation procedure for the given package.
|
||||
--:: string -> ok::boolean, err::string?
|
||||
function Manager:install(package)
|
||||
local cmd = format_cmd(self._cmd.install,
|
||||
{name=self.name, bin=self.bin, package=package})
|
||||
return exec(cmd)
|
||||
-- `...` is a list of alternative names of the package.
|
||||
--:: string... -> ok::boolean, err::string?
|
||||
function Manager:install(package, ...)
|
||||
local ok, err
|
||||
for _, package in ipairs{package, ...} do
|
||||
local cmd = format_cmd(self._cmd.install,
|
||||
{name=self.name, bin=self.bin, package=package})
|
||||
ok, err = exec(cmd)
|
||||
if ok then return true end
|
||||
end
|
||||
return false, err
|
||||
end
|
||||
|
||||
-- List of supported package managers.
|
||||
@@ -70,7 +76,7 @@ local managers = {
|
||||
}),
|
||||
Manager.new("Pacman", "pacman", {
|
||||
sync = "{bin} -Sy --noconfirm",
|
||||
install = "{bin} -S --asdpes --noconfirm {package}",
|
||||
install = "{bin} -S --asdeps --noconfirm {package}",
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -80,7 +86,7 @@ local function find_manager()
|
||||
for _, manager in ipairs(managers) do
|
||||
if manager:test() then return manager end
|
||||
end
|
||||
return nil, "unsupported package manager / linux distro"
|
||||
return nil, "unsupported linux distro: package manager not found"
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -41,7 +41,7 @@ describe("package manager #root", function()
|
||||
local package = "less"
|
||||
assert(not is_installed(package),
|
||||
string.format("expected %q to be not installed", package))
|
||||
assert(pm:install(package))
|
||||
assert(pm:install("alternative", package))
|
||||
assert(is_installed(package))
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user