Skip to content

Commit 57e5a8a

Browse files
authored
fix(installer): update cwd after uv_fs_rename() was successful (#2033)
Also moves to fs.sync calls over fs.async to avoid unnecessary async coroutine overhead.
1 parent 198f075 commit 57e5a8a

File tree

1 file changed

+8
-8
lines changed
  • lua/mason-core/installer/context

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ function InstallContext:promote_cwd()
8686
-- 2. Prepare for renaming cwd to destination
8787
if platform.is.unix then
8888
-- Some Unix systems will raise an error when renaming a directory to a destination that does not already exist.
89-
fs.async.mkdir(install_path)
89+
fs.sync.mkdir(install_path)
9090
end
91-
-- 3. Update cwd
92-
self.cwd:set(install_path)
93-
-- 4. Move the cwd to the final installation directory
94-
local rename_success, rename_err = pcall(fs.async.rename, cwd, install_path)
91+
-- 3. Move the cwd to the final installation directory
92+
local rename_success, rename_err = pcall(fs.sync.rename, cwd, install_path)
9593
if not rename_success then
9694
-- On some file systems, we cannot create the directory before renaming. Therefore, remove it and then rename.
9795
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)
96+
fs.sync.rmdir(install_path)
97+
assert(fs.sync.dir_exists(cwd), "Current working directory no longer exists after retrying uv_fs_rename().")
98+
fs.sync.rename(cwd, install_path)
10199
end
100+
-- 4. Update cwd
101+
self.cwd:set(install_path)
102102
end
103103

104104
---@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)