diff options
| author | Sam-Briney <46232496+Sam-Briney@users.noreply.github.com> | 2025-11-13 21:50:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-14 03:50:44 +0100 |
| commit | 198f07572c0014774fb87371946e0f03b4908bce (patch) | |
| tree | c76c664fd11704310d8a77221a2ff59a5bec4e78 | |
| parent | chore(main): release 2.1.0 (#1996) (diff) | |
| download | mason-198f07572c0014774fb87371946e0f03b4908bce.tar mason-198f07572c0014774fb87371946e0f03b4908bce.tar.gz mason-198f07572c0014774fb87371946e0f03b4908bce.tar.bz2 mason-198f07572c0014774fb87371946e0f03b4908bce.tar.lz mason-198f07572c0014774fb87371946e0f03b4908bce.tar.xz mason-198f07572c0014774fb87371946e0f03b4908bce.tar.zst mason-198f07572c0014774fb87371946e0f03b4908bce.zip | |
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>
| -rw-r--r-- | lua/mason-core/fs.lua | 6 | ||||
| -rw-r--r-- | lua/mason-core/installer/context/init.lua | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lua/mason-core/fs.lua b/lua/mason-core/fs.lua index 5b194c4f..e7f8343f 100644 --- a/lua/mason-core/fs.lua +++ b/lua/mason-core/fs.lua @@ -79,6 +79,12 @@ local function make_module(uv) end ---@param path string + function M.rmdir(path) + log.debug("fs: rmdir", path) + uv.fs_rmdir(path) + end + + ---@param path string ---@param new_path string function M.rename(path, new_path) log.debug("fs: rename", path, new_path) diff --git a/lua/mason-core/installer/context/init.lua b/lua/mason-core/installer/context/init.lua index b22c562b..e0150e18 100644 --- a/lua/mason-core/installer/context/init.lua +++ b/lua/mason-core/installer/context/init.lua @@ -91,7 +91,14 @@ function InstallContext:promote_cwd() -- 3. Update cwd self.cwd:set(install_path) -- 4. Move the cwd to the final installation directory - fs.async.rename(cwd, install_path) + local rename_success, rename_err = pcall(fs.async.rename, cwd, install_path) + if not rename_success then + -- On some file systems, we cannot create the directory before renaming. Therefore, remove it and then rename. + log.trace("Call to uv_fs_rename() while promoting cwd failed.", rename_err) + fs.async.rmdir(install_path) + assert(fs.async.dir_exists(cwd), "Current working directory no longer exists after retrying uv_fs_rename().") + fs.async.rename(cwd, install_path) + end end ---@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). |
