Fix speedup of dictionaries init (#3592)

Revert 338d14edb7 (#3489)
Simply just don't walk into "res/" subdirectories, which is where
resource files should be per startdict specs.
pull/3601/head
poire-z 6 years ago committed by Frans de Jonge
parent d51c184060
commit e389510257

@ -27,35 +27,28 @@ local function getIfosInDir(path)
-- - No sorting, entries are processed in the order the dir_read_name() call -- - No sorting, entries are processed in the order the dir_read_name() call
-- returns them (inodes linked list) -- returns them (inodes linked list)
-- - If entry is a directory, Walk in it first and recurse -- - If entry is a directory, Walk in it first and recurse
-- With a small optimisation to avoid walking dict subdirectories that -- Don't walk into "res/" subdirectories, as per Stardict specs, they
-- may contain many images: if .ifo found, don't recurse subdirectories. -- may contain possibly many resource files (image, audio files...)
-- that could slow down our walk here.
local ifos = {} local ifos = {}
local ok, iter, dir_obj = pcall(lfs.dir, path) local ok, iter, dir_obj = pcall(lfs.dir, path)
if ok then if ok then
local ifo_found = false
local subdirs = {}
for name in iter, dir_obj do for name in iter, dir_obj do
if name ~= "." and name ~= ".." then if name ~= "." and name ~= ".." and name ~= "res" then
local fullpath = path.."/"..name local fullpath = path.."/"..name
if fullpath:match("%.ifo$") then local attributes = lfs.attributes(fullpath)
table.insert(ifos, fullpath) if attributes ~= nil then
ifo_found = true if attributes.mode == "directory" then
elseif not ifo_found then -- don't check for dirs anymore if we found one .ifo local dirifos = getIfosInDir(fullpath) -- recurse
local attributes = lfs.attributes(fullpath) for _, ifo in pairs(dirifos) do
if attributes ~= nil and attributes.mode == "directory" then table.insert(ifos, ifo)
table.insert(subdirs, fullpath) end
elseif fullpath:match("%.ifo$") then
table.insert(ifos, fullpath)
end end
end end
end end
end end
if not ifo_found and #subdirs > 0 then
for _, subdir in pairs(subdirs) do
local dirifos = getIfosInDir(subdir)
for _, ifo in pairs(dirifos) do
table.insert(ifos, ifo)
end
end
end
end end
return ifos return ifos
end end

Loading…
Cancel
Save