Verified Commit b16fba9f authored by Karel Koci's avatar Karel Koci 🤘

Fix bug when directory leading to file had same name as that file

Using comparison to check if we have file or directory was really
really bad idea.
parent 730d61f6
......@@ -602,10 +602,8 @@ function collision_check(current_status, remove_pkgs, add_pkgs)
-- Function adding files to tree. It accepts file path, package it belongs to and boolean new saying if given file is from old or new package.
local function add_file_to_tree(file_path, package, new)
local fname = file_path:match("[^/]+$")
local node = files_tree
for n in file_path:gmatch("[^/]+") do
local tp = (n == fname) and "file" or "dir"
local function add(n, tp)
if not node.nodes[n] then
node.nodes[n] = {path = node.path .. '/' .. n, nodes = {}, new_owner = {}, old_owner = {}}
end
......@@ -614,6 +612,12 @@ function collision_check(current_status, remove_pkgs, add_pkgs)
if not node[n_o_own][tp] then node[n_o_own][tp] = {} end
node[n_o_own][tp][package] = true
end
local fname = file_path:match("[^/]+$") -- we have normalized path so there is no trailing slash
local dpath = file_path:sub(1, -fname:len() - 1) -- cut off fname
for n in dpath:gmatch("[^/]+") do
add(n, "dir")
end
add(fname, "file")
end
-- Populate tree with files from currently installed packages
for name, status in pairs(current_status) do
......
......@@ -592,6 +592,21 @@ function test_collisions()
}
}, col)
-- For "erem" and "rem" see note few lines before this one.
-- We encountered problem with bird4 and bird6 so test for it. It happens when final file has same name as directory leading to it.
local test_pkg = {
["bird6"] = {
["/etc/bird6/init.d/bird6"] = true,
["/etc/bird6/config"] = true
},
["bird4"] = {
["/etc/bird4/init.d/bird4"] = true,
["/etc/bird4/config"] = true
}
}
local col, erem, rem = B.collision_check(status, {}, test_pkg)
assert_table_equal({}, col)
assert_table_equal({}, erem)
assert_table_equal({}, rem)
end
-- Test config_steal and not_installed_confs function
......
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