fix various issues, and add a comment because of a bug in glibc

This commit is contained in:
kyazdani42
2020-06-09 18:59:32 +02:00
parent 899fb177e0
commit 896cc1619a
2 changed files with 19 additions and 9 deletions

View File

@@ -52,7 +52,7 @@ local function create_root(cwd)
end end
function M.update_status(entries, _cwd) function M.update_status(entries, _cwd)
local cwd = _cwd:gsub(' ', '\\ ') local cwd = _cwd:gsub(' ', '\\ '):gsub('%[', '\\['):gsub('%(', '\\(')
local git_root, git_status = get_git_root(cwd) local git_root, git_status = get_git_root(cwd)
if not git_root then if not git_root then
if not create_root(cwd) then if not create_root(cwd) then

View File

@@ -37,6 +37,11 @@ local function file_new(cwd, name)
} }
end end
-- TODO-INFO: sometimes fs_realpath returns nil
-- I expect this be a bug in glibc, because it fails to retrieve the path for some
-- links (for instance libr2.so in /usr/lib) and thus even with a C program realpath fails
-- when it has no real reason to. Maybe there is a reason, but errno is definitely wrong.
-- So we need to check for link_to ~= nil when adding new links to the main tree
local function link_new(cwd, name) local function link_new(cwd, name)
local absolute_path = cwd..'/'..name local absolute_path = cwd..'/'..name
local link_to = luv.fs_realpath(absolute_path) local link_to = luv.fs_realpath(absolute_path)
@@ -114,9 +119,9 @@ function M.refresh_entries(entries, cwd)
end end
local all = { local all = {
{ entries = dirs, fn = dir_new }, { entries = dirs, fn = dir_new, check = function(_, abs) return luv.fs_access(abs, 'R') end },
{ entries = links, fn = link_new }, { entries = links, fn = link_new, check = function(name) return name ~= nil end },
{ entries = files, fn = file_new } { entries = files, fn = file_new, check = function() return true end }
} }
local prev = nil local prev = nil
@@ -124,6 +129,9 @@ function M.refresh_entries(entries, cwd)
for _, name in ipairs(e.entries) do for _, name in ipairs(e.entries) do
if not named_entries[name] then if not named_entries[name] then
local n = e.fn(cwd, name) local n = e.fn(cwd, name)
if not e.check(n.link_to, n.absolute_path) then
goto continue
end
idx = 1 idx = 1
if prev then if prev then
@@ -134,6 +142,7 @@ function M.refresh_entries(entries, cwd)
cached_entries[idx] = name cached_entries[idx] = name
end end
prev = name prev = name
::continue::
end end
end end
end end
@@ -152,6 +161,7 @@ function M.populate(entries, cwd)
while true do while true do
local name, t = luv.fs_scandir_next(handle) local name, t = luv.fs_scandir_next(handle)
if not name then break end if not name then break end
if should_ignore(name) then goto continue end
if t == 'directory' then if t == 'directory' then
table.insert(dirs, name) table.insert(dirs, name)
@@ -160,29 +170,29 @@ function M.populate(entries, cwd)
elseif t == 'link' then elseif t == 'link' then
table.insert(links, name) table.insert(links, name)
end end
::continue::
end end
-- Create Nodes -- -- Create Nodes --
for _, dirname in ipairs(dirs) do for _, dirname in ipairs(dirs) do
local dir = dir_new(cwd, dirname) local dir = dir_new(cwd, dirname)
if not should_ignore(dir.name) and luv.fs_access(dir.absolute_path, 'R') then if luv.fs_access(dir.absolute_path, 'R') then
table.insert(entries, dir) table.insert(entries, dir)
end end
end end
for _, linkname in ipairs(links) do for _, linkname in ipairs(links) do
local link = link_new(cwd, linkname) local link = link_new(cwd, linkname)
if not should_ignore(link.name) then if link.link_to ~= nil then
table.insert(entries, link) table.insert(entries, link)
end end
end end
for _, filename in ipairs(files) do for _, filename in ipairs(files) do
local file = file_new(cwd, filename) local file = file_new(cwd, filename)
if not should_ignore(file.name) then table.insert(entries, file)
table.insert(entries, file)
end
end end
if not icon_config.show_git_icon then if not icon_config.show_git_icon then