aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/mason-core/fs.lua49
-rw-r--r--lua/mason-core/installer/context/InstallContextFs.lua8
2 files changed, 17 insertions, 40 deletions
diff --git a/lua/mason-core/fs.lua b/lua/mason-core/fs.lua
index 597ba3fa..2f620a49 100644
--- a/lua/mason-core/fs.lua
+++ b/lua/mason-core/fs.lua
@@ -7,32 +7,29 @@ local function make_module(uv)
local M = {}
---@param path string
- function M.fstat(path)
- log.trace("fs: fstat", path)
- local fd = uv.fs_open(path, "r", 438)
- local fstat = uv.fs_fstat(fd)
- uv.fs_close(fd)
- return fstat
+ function M.stat(path)
+ log.trace("fs: stat", path)
+ return assert(uv.fs_stat(path))
end
---@param path string
function M.file_exists(path)
log.trace("fs: file_exists", path)
- local ok, fstat = pcall(M.fstat, path)
+ local ok, stat = pcall(M.stat, path)
if not ok then
return false
end
- return fstat.type == "file"
+ return stat.type == "file"
end
---@param path string
function M.dir_exists(path)
log.trace("fs: dir_exists", path)
- local ok, fstat = pcall(M.fstat, path)
+ local ok, stat = pcall(M.stat, path)
if not ok then
return false
end
- return fstat.type == "directory"
+ return stat.type == "directory"
end
---@param path string
@@ -188,33 +185,13 @@ local function make_module(uv)
---@param path string: The full path to the directory to read.
---@return ReaddirEntry[]
function M.readdir(path)
- log.trace("fs: fs_opendir", path)
- local dir = assert(vim.loop.fs_opendir(path, nil, 25))
local all_entries = {}
- local exhausted = false
-
- repeat
- local entries = uv.fs_readdir(dir)
- log.trace("fs: fs_readdir", path, entries)
- if entries and #entries > 0 then
- for i = 1, #entries do
- if entries[i].name and not entries[i].type then
- -- See https://github.com/luvit/luv/issues/660
- local full_path = Path.concat { path, entries[i].name }
- log.trace("fs: fs_readdir falling back to fs_stat to find type", full_path)
- local stat = uv.fs_stat(full_path)
- entries[i].type = stat.type
- end
- all_entries[#all_entries + 1] = entries[i]
- end
- else
- log.trace("fs: fs_readdir exhausted scan", path)
- exhausted = true
- end
- until exhausted
-
- uv.fs_closedir(dir)
-
+ M.ls(path, function(_, entry, type)
+ all_entries[#all_entries + 1] = {
+ name = entry,
+ type = type,
+ }
+ end)
return all_entries
end
diff --git a/lua/mason-core/installer/context/InstallContextFs.lua b/lua/mason-core/installer/context/InstallContextFs.lua
index a36d8410..fd875de0 100644
--- a/lua/mason-core/installer/context/InstallContextFs.lua
+++ b/lua/mason-core/installer/context/InstallContextFs.lua
@@ -88,7 +88,7 @@ function InstallContextFs:chmod_exec(file_path)
local GRP_EXEC = 0x8
local ALL_EXEC = 0x1
local EXEC = bit.bor(USR_EXEC, GRP_EXEC, ALL_EXEC)
- local fstat = self:fstat(file_path)
+ local fstat = self:stat(file_path)
if bit.band(fstat.mode, EXEC) ~= EXEC then
local plus_exec = bit.bor(fstat.mode, EXEC)
log.fmt_debug("Setting exec flags on file %s %o -> %o", file_path, fstat.mode, plus_exec)
@@ -100,13 +100,13 @@ end
---@param file_path string
---@param mode integer
function InstallContextFs:chmod(file_path, mode)
- return fs.async.chmod(path.concat { self.cwd:get(), file_path }, mode)
+ return fs.sync.chmod(path.concat { self.cwd:get(), file_path }, mode)
end
---@async
---@param file_path string
-function InstallContextFs:fstat(file_path)
- return fs.async.fstat(path.concat { self.cwd:get(), file_path })
+function InstallContextFs:stat(file_path)
+ return fs.sync.stat(path.concat { self.cwd:get(), file_path })
end
return InstallContextFs