From 9aaadcf12af081ff28d8c064d4b8835b51a64235 Mon Sep 17 00:00:00 2001 From: BVegNow <117610616+BVegNow@users.noreply.github.com> Date: Sun, 5 Feb 2023 07:27:41 +0800 Subject: feat(windows): manually decompress zstd archives before untar (#963) Co-authored-by: William Boman --- lua/mason-core/managers/std/init.lua | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'lua/mason-core/managers/std/init.lua') diff --git a/lua/mason-core/managers/std/init.lua b/lua/mason-core/managers/std/init.lua index 18c56b21..0b48ea66 100644 --- a/lua/mason-core/managers/std/init.lua +++ b/lua/mason-core/managers/std/init.lua @@ -98,15 +98,25 @@ end ---@async ---@param file string ----@param opts {strip_components:integer}? +---@param opts { strip_components?: integer }? function M.untar(file, opts) opts = opts or {} local ctx = installer.context() + local tarfile = string.gsub(file, ".zst$", "") + if platform.is.win and file ~= tarfile then + ctx.spawn.zstd { + "-d", + "-f", + "-o", + tarfile, + file, + } + end ctx.spawn.tar { opts.strip_components and { "--strip-components", opts.strip_components } or vim.NIL, "--no-same-owner", "-xvf", - file, + tarfile, } pcall(function() ctx.fs:unlink(file) @@ -115,7 +125,25 @@ end ---@async ---@param file string ----@param opts {strip_components: integer?}? +---@param opts { strip_components?: integer }? +function M.untarzst(file, opts) + opts = opts or {} + platform.when { + unix = function() + M.untar(file, opts) + end, + win = function() + local ctx = installer.context() + local uncompressed_tar = file:gsub("%.zst$", "") + ctx.spawn.zstd { "-dfo", uncompressed_tar, file } + M.untar(uncompressed_tar, opts) + end, + } +end + +---@async +---@param file string +---@param opts { strip_components?: integer }? function M.untarxz(file, opts) opts = opts or {} local ctx = installer.context() @@ -126,7 +154,7 @@ function M.untarxz(file, opts) win = function() Result.run_catching(function() win_decompress(file) -- unpack .tar.xz to .tar - local uncompressed_tar = file:gsub(".xz$", "") + local uncompressed_tar = file:gsub("%.xz$", "") M.untar(uncompressed_tar, opts) end):recover(function() ctx.spawn.arc { -- cgit v1.3