From 628d82d6c2ea0f1f3f55b692f8a6b020376a1bd9 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 28 May 2026 11:04:19 +0200 Subject: refactor(fs): use stat instead of fstat --- lua/mason-core/fs.lua | 17 +++++++---------- lua/mason-core/installer/context/InstallContextFs.lua | 8 ++++---- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'lua') diff --git a/lua/mason-core/fs.lua b/lua/mason-core/fs.lua index 0185c30e..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 diff --git a/lua/mason-core/installer/context/InstallContextFs.lua b/lua/mason-core/installer/context/InstallContextFs.lua index c473c0a9..8077070d 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 -- cgit v1.3.1