plugin treeview: fix crash

When the max_project_files is set to a higher value than the allowed
system maximum file descriptors, and opening a project directory that
causes dirmonitor to open a watch on a lot of files or directories, at
least on MacOSX it causes all system.* file functions to return nil
(for too many opened files) which breaks the project files scan.
This commit is contained in:
jgmdev 2022-06-17 15:35:23 -04:00
parent 3c682512e7
commit 173dd3aeb4
1 changed files with 20 additions and 18 deletions

View File

@ -153,28 +153,30 @@ function TreeView:each_item()
count_lines = count_lines + 1 count_lines = count_lines + 1
y = y + h y = y + h
local i = 1 local i = 1
while i <= #dir.files and dir_cached.expanded do if dir.files then -- if consumed max sys file descriptors this can be nil
local item = dir.files[i] while i <= #dir.files and dir_cached.expanded do
local cached = self:get_cached(dir, item, dir.name) local item = dir.files[i]
local cached = self:get_cached(dir, item, dir.name)
coroutine.yield(cached, ox, y, w, h) coroutine.yield(cached, ox, y, w, h)
count_lines = count_lines + 1 count_lines = count_lines + 1
y = y + h y = y + h
i = i + 1 i = i + 1
if not cached.expanded then if not cached.expanded then
if cached.skip then if cached.skip then
i = cached.skip i = cached.skip
else else
local depth = cached.depth local depth = cached.depth
while i <= #dir.files do while i <= #dir.files do
if get_depth(dir.files[i].filename) <= depth then break end if get_depth(dir.files[i].filename) <= depth then break end
i = i + 1 i = i + 1
end
cached.skip = i
end end
cached.skip = i
end end
end end -- while files
end -- while files end
end -- for directories end -- for directories
self.count_lines = count_lines self.count_lines = count_lines
end) end)