fix: use fs_realpath to normalize path (#978)

This commit is contained in:
Xavier Young 2022-02-15 15:33:11 +08:00 committed by GitHub
parent d34ea42254
commit fdf63e572d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 21 deletions

View File

@ -13,7 +13,7 @@ local Explorer = {}
Explorer.__index = Explorer Explorer.__index = Explorer
function Explorer.new(cwd) function Explorer.new(cwd)
cwd = utils.path_normalize(cwd or uv.cwd()) cwd = uv.fs_realpath(cwd or uv.cwd())
return setmetatable({ return setmetatable({
cwd = cwd, cwd = cwd,
nodes = {} nodes = {}

View File

@ -208,24 +208,4 @@ function M.file_exists(path)
return error == nil return error == nil
end end
--- @param num number elements to take
--- @param list table elements
--- @return table
function M.take(num, list)
local t = {}
for i, c in ipairs(list) do
if i > num then break end
table.insert(t, c)
end
return t
end
--- @param path string
--- @return string
function M.path_normalize(path)
local components = vim.split(vim.fn.expand(path), path_separator)
local num_dots = #vim.tbl_filter(function(v) return v == ".." end, components)
return M.path_join(M.take(#components - num_dots * 2, components))
end
return M return M