Fix conflict in treeview for top directories

Happened if a filename has the same name of a top directory.

It will cause a collision in the string to identify the entry into the cache.
This commit is contained in:
Francesco Abbate 2021-01-19 16:39:15 +01:00
parent 9412b3f0d8
commit c2cccf0173
1 changed files with 6 additions and 2 deletions

View File

@ -35,7 +35,11 @@ function TreeView:get_cached(item, dirname)
dir_cache = {}
self.cache[dirname] = dir_cache
end
local t = dir_cache[item.filename]
-- to discriminate top directories from regular files or subdirectories
-- we add ':' at the end of the top directories' filename. it will be
-- used only to identify the entry into the cache.
local cache_name = item.filename .. (item.topdir and ":" or "")
local t = dir_cache[cache_name]
if not t then
t = {}
local basename = common.basename(item.filename)
@ -51,7 +55,7 @@ function TreeView:get_cached(item, dirname)
end
t.name = basename
t.type = item.type
dir_cache[item.filename] = t
dir_cache[cache_name] = t
end
return t
end