From 09fa1d22f5edf0730824d2b222d726c8c81bbdc9 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli <506791+stevearc@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:22:59 -0800 Subject: [PATCH] fix: work around incorrect link detection on windows (#557) * fix: work around incorrect link detection on windows * fix: gracefully handle lstat error on windows --- lua/oil/adapters/files.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lua/oil/adapters/files.lua b/lua/oil/adapters/files.lua index ac56c4e..b7f5363 100644 --- a/lua/oil/adapters/files.lua +++ b/lua/oil/adapters/files.lua @@ -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())