Skip to content

fix(#914): windows/macos file_exists uses fs_open/fs_close rather than fs_stat due to case sensitivity dramas #1988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,24 @@ function M.rename_loaded_buffers(old_path, new_path)
end
end

--- Path exists and is readable. fs_stat is used to test.
--- On windows and macos there are case sensitivity issues with fs_stat; fs_open
--- is used as it do not suffer these issues.
--- @param path string path to file or directory
--- @return boolean
function M.file_exists(path)
local _, error = vim.loop.fs_stat(path)
return error == nil
if M.is_windows or M.is_macos then
local f = vim.loop.fs_open(path, "r", 438)
if type(f) == "number" then
vim.loop.fs_close(f)
return true
else
return false
end
else
local stat = vim.loop.fs_stat(path)
return type(stat) == "table"
end
end

--- @param path string
Expand Down