Integrate modification config check to merge

When merging a package into the system, check if the config files were
modified. Also, provide the hashes of previous version's config files to
the merging function.
parent a5c267f2
......@@ -557,8 +557,22 @@ function dir_ensure(dir)
end
end
-- Merge the given package into the live system and remove the temporary file.
--[[
Merge the given package into the live system and remove the temporary directory.
The confis parameter describes the previous version of the package, not
the current one.
]]
function pkg_merge_files(dir, dirs, files, configs)
if stat(dir) == nil then
--[[
The directory is not there. This looks like the package has
already been merged into place (and we are resuming
from journal), so skip it completely.
]]
DBG("Skipping installation of temporary dir " .. dir .. ", no longer present")
return
end
--[[
First, create the needed directories. Sort them according to
their length, which ensures the parent directories are created
......@@ -578,14 +592,18 @@ function pkg_merge_files(dir, dirs, files, configs)
Now move all the files in place.
]]
for f in pairs(files) do
-- TODO: Handle the configs
DBG("Installing file " .. f)
--[[
TODO: Handle the possibility of the file being already
moved to place, because the previous run has been
interrupted and we resumed from the journal.
]]
move(dir .. f, root_dir .. f)
if stat(dir .. f) == nil then
DBG("File " .. f .. " already installed")
else
DBG("Installing file " .. f)
local hash = configs[f]
local result = root_dir .. f
if hash and config_modified(result, hash) then
WARN("Config file " .. f .. " modified by the user. Backing into " .. f .. "-opkg")
result = result .. "-opkg"
end
move(dir .. f, result)
end
end
-- Remove the original directory
utils.cleanup_dirs({dir})
......
......@@ -82,12 +82,14 @@ function perform(operations)
local files, dirs, configs, control = backend.pkg_examine(pkg_dir)
to_remove[control.Package] = true
to_install[control.Package] = files
local old = status[control.Package] or {}
table.insert(plan, {
op = "install",
dir = pkg_dir,
files = files,
dirs = dirs,
configs = configs,
old_configs = old.Conffiles or {},
control = control
})
else
......@@ -108,7 +110,7 @@ function perform(operations)
for _, op in ipairs(plan) do
if op.op == "install" then
-- TODO: pre-install scripts (who would use such thing anyway?)
backend.pkg_merge_files(op.dir .. "/data", op.dirs, op.files, op.configs)
backend.pkg_merge_files(op.dir .. "/data", op.dirs, op.files, op.old_configs)
end
-- Ignore others, at least for now.
end
......
......@@ -352,7 +352,13 @@ function test_pkg_unpack()
]]
dirs["/usr/share/updater/hashes"] = nil
dirs["/etc/cron.d"] = nil
B.pkg_merge_files(path .. "/data", dirs, files, conffiles)
-- Prepare a config file that was modified by a user
mkdir(test_root .. "/etc")
mkdir(test_root .. "/etc/config")
io.open(test_root .. "/etc/config/updater", "w"):close()
B.pkg_merge_files(path .. "/data", dirs, files, {
["/etc/config/updater"] = "12345678901234567890123456789012"
})
-- The original directory disappeared.
assert_table_equal({
["control"] = "d"
......@@ -365,6 +371,7 @@ function test_pkg_unpack()
./etc
./etc/config
./etc/config/updater
./etc/config/updater-opkg
./etc/init.d
./etc/init.d/updater
./etc/ssl
......@@ -384,6 +391,8 @@ function test_pkg_unpack()
./usr/share/updater/keys/standby.pem
]]), lines2set(stdout))
end, function () chdir(test_root) end, nil, -1, -1, "/usr/bin/find"))
-- Delete the backed-up file, it is not tracked
os.remove(test_root .. "/etc/config/updater-opkg")
-- Now try clearing the package. When we list all the files, it should remove the directories as well.
B.pkg_cleanup_files(files)
assert_table_equal({}, ls(test_root))
......
......@@ -30,7 +30,10 @@ local test_status = {
},
["pkg-name"] = {
Package = "pkg-name",
Canary = true
Canary = true,
Conffiles = {
c = "12345678901234567890123456789012"
}
}
}
local intro = {
......@@ -163,7 +166,7 @@ function test_perform_ok()
},
{
f = "backend.pkg_merge_files",
p = {"pkg_dir/data", {d = true}, {f = true}, {c = "1234567890123456"}}
p = {"pkg_dir/data", {d = true}, {f = true}, {c = "12345678901234567890123456789012"}}
},
{
f = "backend.pkg_merge_control",
......
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