aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers/std.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-10-06 15:17:43 +0200
committerGitHub <noreply@github.com>2021-10-06 15:17:43 +0200
commitd09ada1a3ed7fb35fefc20eb5daa4b767fc73906 (patch)
tree2152516dba481350642db27df018c1f60a3171f1 /lua/nvim-lsp-installer/installers/std.lua
parentwindows: add -UseBasicParsing for iwr calls (diff)
downloadmason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.gz
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.bz2
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.lz
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.xz
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.tar.zst
mason-d09ada1a3ed7fb35fefc20eb5daa4b767fc73906.zip
windows: attempt all common archiver programs (#136)
Diffstat (limited to 'lua/nvim-lsp-installer/installers/std.lua')
-rw-r--r--lua/nvim-lsp-installer/installers/std.lua103
1 files changed, 86 insertions, 17 deletions
diff --git a/lua/nvim-lsp-installer/installers/std.lua b/lua/nvim-lsp-installer/installers/std.lua
index bdd60eca..c7728fe7 100644
--- a/lua/nvim-lsp-installer/installers/std.lua
+++ b/lua/nvim-lsp-installer/installers/std.lua
@@ -1,4 +1,5 @@
local path = require "nvim-lsp-installer.path"
+local fs = require "nvim-lsp-installer.fs"
local process = require "nvim-lsp-installer.process"
local platform = require "nvim-lsp-installer.platform"
local installers = require "nvim-lsp-installer.installers"
@@ -52,15 +53,60 @@ function M.unzip_remote(url, dest)
}
end
-function M.untar(file, opts)
- local default_opts = {
- strip_components = 0,
- }
- opts = vim.tbl_deep_extend("force", default_opts, opts or {})
+function M.untar(file)
return installers.pipe {
function(server, callback, context)
process.spawn("tar", {
- args = { "-xvf", file, "--strip-components", opts.strip_components },
+ args = { "-xvf", file },
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ }, callback)
+ end,
+ installers.always_succeed(M.delete_file(file)),
+ }
+end
+
+local function win_extract(file)
+ return installers.pipe {
+ function(server, callback, context)
+ -- The trademarked "throw shit until it sticks" technique
+ local sevenzip = process.lazy_spawn("7z", {
+ args = { "x", "-y", "-r", file },
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ })
+ local peazip = process.lazy_spawn("peazip", {
+ args = { "-ext2here", path.concat { server.root_dir, file } }, -- peazip require absolute paths, or else!
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ })
+ local winzip = process.lazy_spawn("wzunzip", {
+ args = { file },
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ })
+ process.attempt {
+ jobs = { sevenzip, peazip, winzip },
+ on_finish = callback,
+ }
+ end,
+ installers.always_succeed(M.delete_file(file)),
+ }
+end
+
+local function win_untarxz(file)
+ return installers.pipe {
+ win_extract(file),
+ M.untar(file:gsub(".xz$", "")),
+ }
+end
+
+local function win_arc_unarchive(file)
+ return installers.pipe {
+ function(server, callback, context)
+ context.stdio_sink.stdout "Attempting to unarchive using arc."
+ process.spawn("arc", {
+ args = { "unarchive", file },
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
}, callback)
@@ -69,28 +115,37 @@ function M.untar(file, opts)
}
end
-function M.untarxz_remote(url, tar_opts)
+function M.untarxz_remote(url)
return installers.pipe {
M.download_file(url, "archive.tar.xz"),
- M.untar("archive.tar.xz", tar_opts),
+ installers.when {
+ unix = M.untar "archive.tar.xz",
+ win = installers.first_successful {
+ win_untarxz "archive.tar.xz",
+ win_arc_unarchive "archive.tar.xz",
+ },
+ },
}
end
-function M.untargz_remote(url, tar_opts)
+function M.untargz_remote(url)
return installers.pipe {
M.download_file(url, "archive.tar.gz"),
- M.untar("archive.tar.gz", tar_opts),
+ M.untar "archive.tar.gz",
}
end
function M.gunzip(file)
- return function(server, callback, context)
- process.spawn("gzip", {
- args = { "-d", file },
- cwd = server.root_dir,
- stdio_sink = context.stdio_sink,
- }, callback)
- end
+ return installers.when {
+ unix = function(server, callback, context)
+ process.spawn("gzip", {
+ args = { "-d", file },
+ cwd = server.root_dir,
+ stdio_sink = context.stdio_sink,
+ }, callback)
+ end,
+ win = win_extract(file),
+ }
end
function M.gunzip_remote(url, out_file)
@@ -159,6 +214,20 @@ function M.ensure_executables(executables)
end)
end
+function M.rename(old_path, new_path)
+ return function(server, callback, context)
+ local ok = pcall(
+ fs.rename,
+ path.concat { server.root_dir, old_path },
+ path.concat { server.root_dir, new_path }
+ )
+ if not ok then
+ context.stdio_sink.stderr(("Failed to rename %q to %q.\n"):format(old_path, new_path))
+ end
+ callback(ok)
+ end
+end
+
function M.chmod(flags, files)
return installers.on {
unix = function(server, callback, context)