From 1e2acb0b71dbeec144f2e19f816f995f80b0976e Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 2 Dec 2021 15:05:07 +0100 Subject: server: always delete the tmp install dir if installation fails --- lua/nvim-lsp-installer/server.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lua/nvim-lsp-installer/server.lua') diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua index aeaa5ba2..56ae77b5 100644 --- a/lua/nvim-lsp-installer/server.lua +++ b/lua/nvim-lsp-installer/server.lua @@ -122,9 +122,13 @@ function M.Server:install(version) status_win().install_server(self, version) end +function M.Server:get_tmp_install_dir() + return path.concat { settings.current.install_root_dir, ("%s.tmp"):format(self.name) } +end + ---@param context ServerInstallContext function M.Server:_setup_install_context(context) - context.install_dir = path.concat { settings.current.install_root_dir, ("%s.tmp"):format(self.name) } + context.install_dir = self:get_tmp_install_dir() fs.rm_mkdirp(context.install_dir) if not fs.dir_exists(settings.current.install_root_dir) then @@ -182,6 +186,7 @@ function M.Server:install_attached(context, callback) context.stdio_sink.stderr( ("Failed to promote the temporary installation directory %q.\n"):format(context.install_dir) ) + pcall(fs.rmrf, self:get_tmp_install_dir()) callback(false) return end @@ -195,7 +200,7 @@ function M.Server:install_attached(context, callback) end) callback(true) else - pcall(fs.rmrf, context.install_dir) + pcall(fs.rmrf, self:get_tmp_install_dir()) callback(false) end end), -- cgit v1.2.3-70-g09d2