Skip to content

Commit d222b16

Browse files
Sam-Brineywilliamboman
authored andcommitted
fix(installer): attempt to recover from known fs error while finalizing installation on some file systems (#1933)
Co-authored-by: William Boman <william@redwill.se>
1 parent 580ce3e commit d222b16

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lua/mason-core/fs.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ local function make_module(uv)
7878
end
7979
end
8080

81+
---@param path string
82+
function M.rmdir(path)
83+
log.debug("fs: rmdir", path)
84+
uv.fs_rmdir(path)
85+
end
86+
8187
---@param path string
8288
---@param new_path string
8389
function M.rename(path, new_path)

lua/mason-core/installer/context/init.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ function InstallContext:promote_cwd()
9191
-- 3. Update cwd
9292
self.cwd:set(install_path)
9393
-- 4. Move the cwd to the final installation directory
94-
fs.async.rename(cwd, install_path)
94+
local rename_success, rename_err = pcall(fs.async.rename, cwd, install_path)
95+
if not rename_success then
96+
-- On some file systems, we cannot create the directory before renaming. Therefore, remove it and then rename.
97+
log.trace("Call to uv_fs_rename() while promoting cwd failed.", rename_err)
98+
fs.async.rmdir(install_path)
99+
assert(fs.async.dir_exists(cwd), "Current working directory no longer exists after retrying uv_fs_rename().")
100+
fs.async.rename(cwd, install_path)
101+
end
95102
end
96103

97104
---@param rel_path string The relative path from the current working directory to change cwd to. Will only restore to the initial cwd after execution of fn (if provided).

0 commit comments

Comments
 (0)