pkg: Not-installed flag

Don't get confused if you see it. Also, produce it in case we leave a
modified config behind (but listing only the modified configs, removing
the rest).
parent 14cfe59e
......@@ -690,17 +690,22 @@ function pkg_merge_control(dir, name, files)
events_wait(unpack(events))
end
function pkg_config_info(f, configs)
-- Make sure there are no // in there, which would confuse the directory cleaning code
f = f:gsub("/+", "/")
local path = root_dir .. f
local hash = configs[f]
return path, hash and config_modified(path, hash)
end
--[[
Remove files provided as a set and any directories which became
empty by doing so (recursively).
]]
function pkg_cleanup_files(files, rm_configs)
for f in pairs(files) do
-- Make sure there are no // in there, which would confuse the directory cleaning code
f = f:gsub("/+", "/")
local path = root_dir .. f
local hash = rm_configs[f]
if hash and config_modified(path, hash) then
local path, config_mod = pkg_config_info(f, rm_configs)
if config_mod then
DBG("Not removing config " .. f .. ", as it has been modified")
else
DBG("Removing file " .. path)
......@@ -789,7 +794,7 @@ function control_cleanup(status)
local pname = file:match("^([^%.]+)%.")
if not pname then
WARN("Control file " .. file .. " has a wrong name format")
elseif not status[pname] then
elseif utils.multi_index(status, pname, "Status", 3) ~= "installed" then
DBG("Removing control file " .. file)
local _, err = os.remove(info_dir .. "/" .. file)
if err then
......
......@@ -135,7 +135,7 @@ local function pkg_move(status, plan, errors_collected)
utils.table_merge(all_configs, op.old_configs)
-- Unfortunately, we need to merge the control files first, otherwise the maintainer scripts won't run. They expect to live in the info dir when they are run. And we need to run the preinst script before merging the files.
backend.pkg_merge_control(op.dir .. "/control", op.control.Package, op.control.files)
if status[op.control.Package] then
if utils.multi_index(status, op.control.Package, "Status", 3) == "installed" then
-- There's a previous version. So this is an upgrade.
script(errors_collected, op.control.Package, "preinst", "upgrade", status[op.control.Package].Version)
else
......@@ -155,7 +155,19 @@ local function pkg_scripts(status, plan, removes, to_install, errors_collected,
script(errors_collected, op.control.Package, "postinst", "configure")
elseif op.op == "remove" and not to_install[op.name] then
utils.table_merge(all_configs, status[op.name].Conffiles or {})
status[op.name] = nil
local cfiles = status[op.name].Conffiles or {}
for f in pairs(cfiles) do
local path, modified = backend.pkg_config_info(f, cfiles)
if not modified then
cfiles[f] = nil
end
end
if next(cfiles) then
-- Keep the package info there, with the relevant modified configs
status[op.name].Status = {"install", "user", "not-installed"}
else
status[op.name] = nil
end
script(errors_collected, op.name, "prerm", "remove")
end
end
......
......@@ -619,13 +619,19 @@ function test_control_cleanup()
The control_cleanup doesn't care about the content of the packages, so be lazy a bit.
]]
local function pkg_gen(name)
return {
Package = name,
Status = {"install", "user", "installed"}
}
end
B.control_cleanup({
pkg1 = true,
pkg2 = true
pkg1 = pkg_gen "pkg1",
pkg2 = pkg_gen "pkg2"
})
assert_table_equal(all_files, ls(test_dir))
-- Drop the things belonging to pkg2
B.control_cleanup({ pkg1 = true })
B.control_cleanup({ pkg1 = pkg_gen "pkg1" })
all_files["pkg2.control"] = nil
all_files["pkg2.xyz.abc"] = nil
assert_table_equal(all_files, ls(test_dir))
......
......@@ -30,7 +30,8 @@ local test_status = {
Package = "pkg-rem",
Conffiles = {
remconf = "12345678901234567890123456789012"
}
},
Status = {"install", "user", "installed"}
},
["pkg-name"] = {
Package = "pkg-name",
......@@ -38,7 +39,8 @@ local test_status = {
Version = "0",
Conffiles = {
c = "12345678901234567890123456789012"
}
},
Status = {"install", "user", "installed"}
}
}
local intro = {
......@@ -121,7 +123,7 @@ local function mocks_install()
mock_gen("backend.dir_ensure")
mock_gen("backend.status_parse", function () return utils.clone(test_status) end)
mock_gen("backend.pkg_unpack", function () return "pkg_dir" end)
mock_gen("backend.pkg_examine", function () return {f = true}, {d = true}, {c = "1234567890123456"}, {Package = "pkg-name", files = {f = true}, Conffiles = {c = "1234567890123456"}, Version = "1"} end)
mock_gen("backend.pkg_examine", function () return {f = true}, {d = true}, {c = "1234567890123456"}, {Package = "pkg-name", files = {f = true}, Conffiles = {c = "1234567890123456"}, Version = "1", Status = {"install", "user", "installed"}} end)
mock_gen("backend.collision_check", function () return {}, {} end)
mock_gen("backend.pkg_merge_files")
mock_gen("backend.pkg_cleanup_files")
......@@ -135,6 +137,9 @@ local function mocks_install()
return true, ""
end
end)
mock_gen("backend.pkg_config_info", function (f, configs)
return f, false
end)
mock_gen("utils.cleanup_dirs")
mock_gen("journal.fresh")
mock_gen("journal.finish")
......@@ -210,7 +215,8 @@ function test_perform_ok()
Package = "pkg-name",
Conffiles = { c = "1234567890123456" },
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "installed"}
}
status_mod["pkg-rem"] = nil
local expected = tables_join(intro, {
......@@ -235,7 +241,8 @@ function test_perform_ok()
Conffiles = { c = "1234567890123456" },
Package = "pkg-name",
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "installed"}
},
dir = "pkg_dir",
dirs = { d = true },
......@@ -284,11 +291,13 @@ function test_perform_ok()
Conffiles = { c = "1234567890123456" },
Package = "pkg-name",
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "installed"}
},
["pkg-rem"] = {
Package = "pkg-rem",
Conffiles = { remconf = "12345678901234567890123456789012" }
Conffiles = { remconf = "12345678901234567890123456789012" },
Status = {"install", "user", "installed"}
}
},
{},
......@@ -299,6 +308,10 @@ function test_perform_ok()
f = "backend.script_run",
p = {"pkg-name", "postinst", "configure"}
},
{
f = "backend.pkg_config_info",
p = {"remconf", { remconf = "12345678901234567890123456789012" } }
},
{
f = "backend.script_run",
p = {"pkg-rem", "prerm", "remove"}
......@@ -320,7 +333,8 @@ function test_perform_ok()
Conffiles = { c = "1234567890123456" },
Package = "pkg-name",
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "installed"}
}
},
{ ["pkg-name"] = { ["postinst"] = "Fake failed postinst" } }
......@@ -469,7 +483,8 @@ function test_recover_late()
Conffiles = { c = "1234567890123456" },
Package = "pkg-name",
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "instatalled"}
},
dir = "pkg_dir",
dirs = { d = true },
......@@ -487,7 +502,8 @@ function test_recover_late()
Conffiles = { c = "1234567890123456" },
Package = "pkg-name",
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "installed"}
},
["pkg-rem"] = {
Package = "pkg-rem"
......@@ -501,7 +517,8 @@ function test_recover_late()
Conffiles = { c = "1234567890123456" },
Package = "pkg-name",
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "installed"}
}
},
{ ["pkg-name"] = { ["postinst"] = "Fake failed postinst" } }
......@@ -518,7 +535,8 @@ function test_recover_late()
Package = "pkg-name",
Conffiles = { c = "1234567890123456" },
Version = "1",
files = { f = true }
files = { f = true },
Status = {"install", "user", "installed"}
}
status_mod["pkg-rem"] = nil
local intro_mod = utils.clone(intro)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment