diff options
| -rw-r--r-- | lua/mason-core/fs.lua | 17 | ||||
| -rw-r--r-- | lua/mason-core/installer/context/InstallContextFs.lua | 8 | ||||
| -rw-r--r-- | tests/mason-core/installer/compiler/link_spec.lua | 16 |
3 files changed, 19 insertions, 22 deletions
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 diff --git a/tests/mason-core/installer/compiler/link_spec.lua b/tests/mason-core/installer/compiler/link_spec.lua index 62777bc9..6c77bbc6 100644 --- a/tests/mason-core/installer/compiler/link_spec.lua +++ b/tests/mason-core/installer/compiler/link_spec.lua @@ -22,10 +22,10 @@ describe("registry linker", function() local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") - stub(ctx.fs, "fstat") + stub(ctx.fs, "stat") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "exec.sh").returns(true) - ctx.fs.fstat.on_call_with(match.is_ref(ctx.fs), "exec.sh").returns { + ctx.fs.stat.on_call_with(match.is_ref(ctx.fs), "exec.sh").returns { mode = 493, -- 0755 } @@ -59,10 +59,10 @@ describe("registry linker", function() local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") - stub(ctx.fs, "fstat") + stub(ctx.fs, "stat") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "exec.sh").returns(true) - ctx.fs.fstat.on_call_with(match.is_ref(ctx.fs), "exec.sh").returns { + ctx.fs.stat.on_call_with(match.is_ref(ctx.fs), "exec.sh").returns { mode = 420, -- 0644 } @@ -88,10 +88,10 @@ describe("registry linker", function() local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") - stub(ctx.fs, "fstat") + stub(ctx.fs, "stat") ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), "v1.0.0-exec.sh").returns(true) - ctx.fs.fstat.on_call_with(match.is_ref(ctx.fs), "v1.0.0-exec.sh").returns { + ctx.fs.stat.on_call_with(match.is_ref(ctx.fs), "v1.0.0-exec.sh").returns { mode = 493, -- 0755 } @@ -120,7 +120,7 @@ describe("registry linker", function() local ctx = test_helpers.create_context() stub(ctx.fs, "file_exists") stub(ctx.fs, "chmod") - stub(ctx.fs, "fstat") + stub(ctx.fs, "stat") local matrix = { ["cargo:executable"] = "bin/executable", @@ -135,7 +135,7 @@ describe("registry linker", function() for bin, path in pairs(matrix) do ctx.fs.file_exists.on_call_with(match.is_ref(ctx.fs), path).returns(true) - ctx.fs.fstat.on_call_with(match.is_ref(ctx.fs), path).returns { + ctx.fs.stat.on_call_with(match.is_ref(ctx.fs), path).returns { mode = 493, -- 0755 } |
