auditd: pkg.Manager supports alternative names in install()

This commit is contained in:
Aleksey Nikitin
2023-01-30 14:53:19 +03:00
parent 4ea8a4bb93
commit 665fc773ec
3 changed files with 16 additions and 10 deletions
+2 -2
View File
@@ -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)
+13 -7
View File
@@ -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 {
+1 -1
View File
@@ -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)