Commit d65755d0 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

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) ...@@ -557,8 +557,22 @@ function dir_ensure(dir)
end end
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) 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 First, create the needed directories. Sort them according to
their length, which ensures the parent directories are created their length, which ensures the parent directories are created
...@@ -578,14 +592,18 @@ function pkg_merge_files(dir, dirs, files, configs) ...@@ -578,14 +592,18 @@ function pkg_merge_files(dir, dirs, files, configs)
Now move all the files in place. Now move all the files in place.
]] ]]
for f in pairs(files) do for f in pairs(files) do
-- TODO: Handle the configs if stat(dir .. f) == nil then
DBG("Installing file " .. f) DBG("File " .. f .. " already installed")
--[[ else
TODO: Handle the possibility of the file being already DBG("Installing file " .. f)
moved to place, because the previous run has been local hash = configs[f]
interrupted and we resumed from the journal. local result = root_dir .. f
]] if hash and config_modified(result, hash) then
move(dir .. f, root_dir .. f) WARN("Config file " .. f .. " modified by the user. Backing into " .. f .. "-opkg")
result = result .. "-opkg"
end
move(dir .. f, result)
end
end end
-- Remove the original directory -- Remove the original directory
utils.cleanup_dirs({dir}) utils.cleanup_dirs({dir})
......
...@@ -82,12 +82,14 @@ function perform(operations) ...@@ -82,12 +82,14 @@ function perform(operations)
local files, dirs, configs, control = backend.pkg_examine(pkg_dir) local files, dirs, configs, control = backend.pkg_examine(pkg_dir)
to_remove[control.Package] = true to_remove[control.Package] = true
to_install[control.Package] = files to_install[control.Package] = files
local old = status[control.Package] or {}
table.insert(plan, { table.insert(plan, {
op = "install", op = "install",
dir = pkg_dir, dir = pkg_dir,
files = files, files = files,
dirs = dirs, dirs = dirs,
configs = configs, configs = configs,
old_configs = old.Conffiles or {},
control = control control = control
}) })
else else
...@@ -108,7 +110,7 @@ function perform(operations) ...@@ -108,7 +110,7 @@ function perform(operations)
for _, op in ipairs(plan) do for _, op in ipairs(plan) do
if op.op == "install" then if op.op == "install" then
-- TODO: pre-install scripts (who would use such thing anyway?) -- 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 end
-- Ignore others, at least for now. -- Ignore others, at least for now.
end end
......
...@@ -352,7 +352,13 @@ function test_pkg_unpack() ...@@ -352,7 +352,13 @@ function test_pkg_unpack()
]] ]]
dirs["/usr/share/updater/hashes"] = nil dirs["/usr/share/updater/hashes"] = nil
dirs["/etc/cron.d"] = 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. -- The original directory disappeared.
assert_table_equal({ assert_table_equal({
["control"] = "d" ["control"] = "d"
...@@ -365,6 +371,7 @@ function test_pkg_unpack() ...@@ -365,6 +371,7 @@ function test_pkg_unpack()
./etc ./etc
./etc/config ./etc/config
./etc/config/updater ./etc/config/updater
./etc/config/updater-opkg
./etc/init.d ./etc/init.d
./etc/init.d/updater ./etc/init.d/updater
./etc/ssl ./etc/ssl
...@@ -384,6 +391,8 @@ function test_pkg_unpack() ...@@ -384,6 +391,8 @@ function test_pkg_unpack()
./usr/share/updater/keys/standby.pem ./usr/share/updater/keys/standby.pem
]]), lines2set(stdout)) ]]), lines2set(stdout))
end, function () chdir(test_root) end, nil, -1, -1, "/usr/bin/find")) 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. -- Now try clearing the package. When we list all the files, it should remove the directories as well.
B.pkg_cleanup_files(files) B.pkg_cleanup_files(files)
assert_table_equal({}, ls(test_root)) assert_table_equal({}, ls(test_root))
......
...@@ -30,7 +30,10 @@ local test_status = { ...@@ -30,7 +30,10 @@ local test_status = {
}, },
["pkg-name"] = { ["pkg-name"] = {
Package = "pkg-name", Package = "pkg-name",
Canary = true Canary = true,
Conffiles = {
c = "12345678901234567890123456789012"
}
} }
} }
local intro = { local intro = {
...@@ -163,7 +166,7 @@ function test_perform_ok() ...@@ -163,7 +166,7 @@ function test_perform_ok()
}, },
{ {
f = "backend.pkg_merge_files", 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", 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