From 3f76fe26ddba6e6608982bbb89d80c3b1326baeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Tue, 2 Jun 2015 14:15:02 +0300 Subject: sqdb-build: fix pruning to not delete locked entries --- src/sqdb-build.lua | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/sqdb-build.lua b/src/sqdb-build.lua index 2806bb2..2e9af22 100755 --- a/src/sqdb-build.lua +++ b/src/sqdb-build.lua @@ -76,7 +76,7 @@ local function get_domain(domain, locked) end entry = child end - return child + return entry end local function get_path(domain_entry, path, locked) @@ -217,21 +217,22 @@ local function enum_all(cb) end end -local function prune_paths(paths, category) - local path, pdata, cat +local function prune_paths(paths, category, locked) + local path, pdata, cat, lock local num_paths = 0 for path, pdata in pairs(paths) do local sub_paths = 0 cat = pdata.category or category + lock = pdata.locked or locked if pdata.paths ~= nil then - sub_paths = prune_paths(pdata.paths, cat) + sub_paths = prune_paths(pdata.paths, cat, lock) if sub_paths == 0 then pdata.paths = nil end end - if cat == category and sub_paths == 0 then + if cat == category and lock == locked and sub_paths == 0 then paths[path] = nil else num_paths = num_paths + 1 @@ -241,15 +242,16 @@ local function prune_paths(paths, category) return num_paths end -local function prune_tree(d, pcategory) +local function prune_tree(d, pcategory, plocked) local num_childs = 0 local num_paths = 0 - local cat + local cat, locked cat = d.category or pcategory + locked = d.locked or plocked if d.children ~= nil then for n, child in pairs(d.children) do - if prune_tree(child, cat, n) then + if prune_tree(child, cat, locked) then d.children[n] = nil else num_childs = num_childs + 1 @@ -262,12 +264,12 @@ local function prune_tree(d, pcategory) end --print(name, d.category, category, d.num_paths, num_childs) if d.paths ~= nil then - num_paths = prune_paths(d.paths, cat) + num_paths = prune_paths(d.paths, cat, locked) if num_paths == 0 then d.paths = nil end end - if d.category == pcategory and num_paths == 0 and num_childs == 0 then + if d.category == pcategory and d.locked == plocked and num_paths == 0 and num_childs == 0 then --num_pruned_leafs = num_pruned_leafs + 1 return true end -- cgit v1.2.3