diff options
| author | William Boman <william@redwill.se> | 2023-04-03 01:43:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 01:43:37 +0200 |
| commit | 46abd3ff86c74294fed9a530ec872ec7a4680bef (patch) | |
| tree | 1f530d70de1fc4efe1259affe0976f6a73f47505 /lua/mason-registry/sources/github.lua | |
| parent | chore: migrate packages (#1173) (diff) | |
| download | mason-46abd3ff86c74294fed9a530ec872ec7a4680bef.tar mason-46abd3ff86c74294fed9a530ec872ec7a4680bef.tar.gz mason-46abd3ff86c74294fed9a530ec872ec7a4680bef.tar.bz2 mason-46abd3ff86c74294fed9a530ec872ec7a4680bef.tar.lz mason-46abd3ff86c74294fed9a530ec872ec7a4680bef.tar.xz mason-46abd3ff86c74294fed9a530ec872ec7a4680bef.tar.zst mason-46abd3ff86c74294fed9a530ec872ec7a4680bef.zip | |
feat: vendor zzlib for unzip (#1174)
Download data of the registry suggest that ~10-18% struggle to unpack the registry archive, with the drop-off occurring in the `unzip` step. Being able to unpack the registry is a very crucial component of mason.nvim, which warrants vendoring [zzlib](https://github.com/zerkman/zzlib) to allow unpacking it entirely in Lua.
Diffstat (limited to 'lua/mason-registry/sources/github.lua')
| -rw-r--r-- | lua/mason-registry/sources/github.lua | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/lua/mason-registry/sources/github.lua b/lua/mason-registry/sources/github.lua index 7920e0d7..f4fd837a 100644 --- a/lua/mason-registry/sources/github.lua +++ b/lua/mason-registry/sources/github.lua @@ -45,7 +45,7 @@ function GitHubRegistrySource.new(spec) end function GitHubRegistrySource:is_installed() - return fs.sync.file_exists(self.data_file) + return fs.sync.file_exists(self.data_file) and fs.sync.file_exists(self.info_file) end function GitHubRegistrySource:reload() @@ -108,6 +108,8 @@ end ---@async function GitHubRegistrySource:install() + local zzlib = require "mason-vendor.zzlib" + return Result.try(function(try) local version = self.spec.version if self:is_installed() and version ~= nil then @@ -132,31 +134,15 @@ function GitHubRegistrySource:install() log.trace("Resolved latest registry version", self, version) end - try(fetch(settings.current.github.download_url_template:format(self.spec.repo, version, "registry.json.zip"), { - out_file = path.concat { self.root_dir, "registry.json.zip" }, - }):map_err(_.always "Failed to download registry.json.zip.")) - - platform.when { - unix = function() - try(spawn.unzip({ "-o", "registry.json.zip", cwd = self.root_dir }):map_err(function(err) - return ("Failed to unpack registry contents: %s"):format(err.stderr) - end)) - end, - win = function() - local powershell = require "mason-core.managers.powershell" - powershell - .command( - ("Microsoft.PowerShell.Archive\\Expand-Archive -Force -Path %q -DestinationPath ."):format "registry.json.zip", - { - cwd = self.root_dir, - } - ) - :map_err(function(err) - return ("Failed to unpack registry contents: %s"):format(err.stderr) - end) - end, - } - pcall(fs.async.unlink, path.concat { self.root_dir, "registry.json.zip" }) + local zip_buffer = try( + fetch(settings.current.github.download_url_template:format(self.spec.repo, version, "registry.json.zip")):map_err( + _.always "Failed to download registry archive." + ) + ) + local registry_contents = try( + Result.pcall(zzlib.unzip, zip_buffer, "registry.json") + :map_err(_.always "Failed to unpack registry archive.") + ) local checksums = try( fetch(settings.current.github.download_url_template:format(self.spec.repo, version, "checksums.txt")):map_err( @@ -164,6 +150,7 @@ function GitHubRegistrySource:install() ) ) + try(Result.pcall(fs.async.write_file, self.data_file, registry_contents)) try(Result.pcall( fs.async.write_file, self.info_file, |
