From 665fc773ec1aa2da37a0f9f5bdd323d38c13fcf6 Mon Sep 17 00:00:00 2001 From: Aleksey Nikitin Date: Mon, 30 Jan 2023 14:53:19 +0300 Subject: [PATCH] auditd: pkg.Manager supports alternative names in install() --- auditd/1.0.0/cmodule/exec_spec.lua | 4 ++-- auditd/1.0.0/cmodule/pkg.lua | 20 +++++++++++++------- auditd/1.0.0/cmodule/pkg_spec.lua | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/auditd/1.0.0/cmodule/exec_spec.lua b/auditd/1.0.0/cmodule/exec_spec.lua index 327585b..1be107c 100644 --- a/auditd/1.0.0/cmodule/exec_spec.lua +++ b/auditd/1.0.0/cmodule/exec_spec.lua @@ -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) diff --git a/auditd/1.0.0/cmodule/pkg.lua b/auditd/1.0.0/cmodule/pkg.lua index 458c0b2..39131ba 100644 --- a/auditd/1.0.0/cmodule/pkg.lua +++ b/auditd/1.0.0/cmodule/pkg.lua @@ -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 { diff --git a/auditd/1.0.0/cmodule/pkg_spec.lua b/auditd/1.0.0/cmodule/pkg_spec.lua index 7863c1d..c6f7b6a 100644 --- a/auditd/1.0.0/cmodule/pkg_spec.lua +++ b/auditd/1.0.0/cmodule/pkg_spec.lua @@ -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)