fix: work around incorrect link detection on windows (#557)
* fix: work around incorrect link detection on windows * fix: gracefully handle lstat error on windows
This commit is contained in:
parent
7c26a59ac0
commit
09fa1d22f5
1 changed files with 28 additions and 0 deletions
|
|
@ -351,6 +351,34 @@ local function fetch_entry_metadata(parent_dir, entry, require_stat, cb)
|
|||
end
|
||||
end
|
||||
|
||||
-- On windows, sometimes the entry type from fs_readdir is "link" but the actual type is not.
|
||||
-- See https://github.com/stevearc/oil.nvim/issues/535
|
||||
if fs.is_windows then
|
||||
local old_fetch_metadata = fetch_entry_metadata
|
||||
fetch_entry_metadata = function(parent_dir, entry, require_stat, cb)
|
||||
if entry[FIELD_TYPE] == "link" then
|
||||
local entry_path = fs.posix_to_os_path(parent_dir .. entry[FIELD_NAME])
|
||||
uv.fs_lstat(entry_path, function(stat_err, stat)
|
||||
if stat_err then
|
||||
log.warn("Error lstat link file %s: %s", entry_path, stat_err)
|
||||
return old_fetch_metadata(parent_dir, entry, require_stat, cb)
|
||||
end
|
||||
assert(stat)
|
||||
entry[FIELD_TYPE] = stat.type
|
||||
local meta = entry[FIELD_META]
|
||||
if not meta then
|
||||
meta = {}
|
||||
entry[FIELD_META] = meta
|
||||
end
|
||||
meta.stat = stat
|
||||
old_fetch_metadata(parent_dir, entry, require_stat, cb)
|
||||
end)
|
||||
else
|
||||
return old_fetch_metadata(parent_dir, entry, require_stat, cb)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param url string
|
||||
---@param column_defs string[]
|
||||
---@param cb fun(err?: string, entries?: oil.InternalEntry[], fetch_more?: fun())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue