diff options
| author | William Boman <william@redwill.se> | 2023-06-28 22:00:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-28 22:00:41 +0200 |
| commit | 10da1a33b4ac24ad4d76a9af91871720ac6b65e4 (patch) | |
| tree | 585133a0afd288f349802ae65726e59ab6e1efab /lua | |
| parent | chore(main): release 1.5.0 (#1375) (diff) | |
| download | mason-10da1a33b4ac24ad4d76a9af91871720ac6b65e4.tar mason-10da1a33b4ac24ad4d76a9af91871720ac6b65e4.tar.gz mason-10da1a33b4ac24ad4d76a9af91871720ac6b65e4.tar.bz2 mason-10da1a33b4ac24ad4d76a9af91871720ac6b65e4.tar.lz mason-10da1a33b4ac24ad4d76a9af91871720ac6b65e4.tar.xz mason-10da1a33b4ac24ad4d76a9af91871720ac6b65e4.tar.zst mason-10da1a33b4ac24ad4d76a9af91871720ac6b65e4.zip | |
fix(linker): ensure exec wrapper target is executable (#1380)
Fixes #1368.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/mason-core/installer/context.lua | 20 | ||||
| -rw-r--r-- | lua/mason-core/installer/registry/link.lua | 20 |
2 files changed, 21 insertions, 19 deletions
diff --git a/lua/mason-core/installer/context.lua b/lua/mason-core/installer/context.lua index 52fbcf16..b12b540f 100644 --- a/lua/mason-core/installer/context.lua +++ b/lua/mason-core/installer/context.lua @@ -125,6 +125,23 @@ end ---@async ---@param file_path string +function ContextualFs:chmod_exec(file_path) + local bit = require "bit" + -- see chmod(2) + local USR_EXEC = 0x40 + local GRP_EXEC = 0x8 + local ALL_EXEC = 0x1 + local EXEC = bit.bor(USR_EXEC, GRP_EXEC, ALL_EXEC) + local fstat = self:fstat(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) + self:chmod(file_path, plus_exec) -- chmod +x + end +end + +---@async +---@param file_path string ---@param mode integer function ContextualFs:chmod(file_path, mode) return fs.async.chmod(path.concat { self.cwd:get(), file_path }, mode) @@ -316,6 +333,9 @@ function InstallContext:write_exec_wrapper(new_executable_rel_path, target_execu if not self.fs:file_exists(target_executable_rel_path) then error(("Cannot write exec wrapper for path %q as it doesn't exist."):format(target_executable_rel_path), 0) end + if platform.is.unix then + self.fs:chmod_exec(target_executable_rel_path) + end return self:write_shell_exec_wrapper( new_executable_rel_path, ("%q"):format(path.concat { diff --git a/lua/mason-core/installer/registry/link.lua b/lua/mason-core/installer/registry/link.lua index 108c4233..85e751b7 100644 --- a/lua/mason-core/installer/registry/link.lua +++ b/lua/mason-core/installer/registry/link.lua @@ -129,24 +129,6 @@ local bin_delegates = { end, } ----@async ----@param ctx InstallContext ----@param target string -local function chmod_exec(ctx, target) - local bit = require "bit" - -- see chmod(2) - local USR_EXEC = 0x40 - local GRP_EXEC = 0x8 - local ALL_EXEC = 0x1 - local EXEC = bit.bor(USR_EXEC, GRP_EXEC, ALL_EXEC) - local fstat = ctx.fs:fstat(target) - 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", target, fstat.mode, plus_exec) - ctx.fs:chmod(target, plus_exec) -- chmod +x - end -end - ---Expands bin specification from spec and registers bins to be linked. ---@async ---@param ctx InstallContext @@ -187,7 +169,7 @@ local function expand_bin(ctx, spec, purl, source) end if platform.is.unix then - chmod_exec(ctx, target) + ctx.fs:chmod_exec(target) end expanded_bin_table[bin] = target |
