aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2026-05-30 15:52:15 +0200
committerGitHub <noreply@github.com>2026-05-30 15:52:15 +0200
commit6daa74748ff63efcf24fb66112412c03df08be72 (patch)
treedf2a931b1f19cf43fc24e4b733cd83ab07d21b50
parentfix(fs): implement rmrf natively via libuv (#2098) (diff)
downloadmason-6daa74748ff63efcf24fb66112412c03df08be72.tar
mason-6daa74748ff63efcf24fb66112412c03df08be72.tar.gz
mason-6daa74748ff63efcf24fb66112412c03df08be72.tar.bz2
mason-6daa74748ff63efcf24fb66112412c03df08be72.tar.lz
mason-6daa74748ff63efcf24fb66112412c03df08be72.tar.xz
mason-6daa74748ff63efcf24fb66112412c03df08be72.tar.zst
mason-6daa74748ff63efcf24fb66112412c03df08be72.zip
refactor(fs): implement mkdirp natively via libuv (#2100)
-rw-r--r--lua/mason-core/fs.lua16
-rw-r--r--lua/mason-core/installer/context/InstallContextFs.lua2
-rw-r--r--lua/mason-core/installer/linker.lua2
-rw-r--r--lua/mason-registry/sources/github.lua2
-rw-r--r--tests/mason-core/fs_spec.lua13
-rw-r--r--tests/mason-core/installer/linker_spec.lua12
6 files changed, 32 insertions, 15 deletions
diff --git a/lua/mason-core/fs.lua b/lua/mason-core/fs.lua
index 5decd3ca..597ba3fa 100644
--- a/lua/mason-core/fs.lua
+++ b/lua/mason-core/fs.lua
@@ -1,5 +1,5 @@
local Path = require "mason-core.path"
-local a = require "mason-core.async"
+local _ = require "mason-core.functional"
local log = require "mason-core.log"
local settings = require "mason.settings"
@@ -123,12 +123,16 @@ local function make_module(uv)
---@param path string
function M.mkdirp(path)
log.debug("fs: mkdirp", path)
- if vim.in_fast_event() then
- a.scheduler()
+ local normalized_path = vim.fs.normalize(path)
+ local path_components = vim.split(normalized_path, "/", { plain = true })
+ if vim.fn.has "win32" ~= 1 then
+ path_components[1] = "/"
end
- if vim.fn.mkdir(path, "p") ~= 1 then
- log.debug "fs: mkdirp failed"
- error(("mkdirp: Could not create directory %q."):format(path))
+ for i = 1, #path_components, 1 do
+ local current_path = vim.fs.joinpath(unpack(_.take(i, path_components)))
+ if not M.dir_exists(current_path) then
+ M.mkdir(current_path)
+ end
end
end
diff --git a/lua/mason-core/installer/context/InstallContextFs.lua b/lua/mason-core/installer/context/InstallContextFs.lua
index c473c0a9..a36d8410 100644
--- a/lua/mason-core/installer/context/InstallContextFs.lua
+++ b/lua/mason-core/installer/context/InstallContextFs.lua
@@ -76,7 +76,7 @@ end
---@async
---@param dir_path string
function InstallContextFs:mkdirp(dir_path)
- return fs.async.mkdirp(path.concat { self.cwd:get(), dir_path })
+ return fs.sync.mkdirp(path.concat { self.cwd:get(), dir_path })
end
---@async
diff --git a/lua/mason-core/installer/linker.lua b/lua/mason-core/installer/linker.lua
index 415f61eb..7fff6d89 100644
--- a/lua/mason-core/installer/linker.lua
+++ b/lua/mason-core/installer/linker.lua
@@ -122,7 +122,7 @@ local function link(context, link_context, link_fn)
a.scheduler()
local dir = vim.fn.fnamemodify(new_abs_path, ":h")
if not fs.async.dir_exists(dir) then
- try(Result.pcall(fs.async.mkdirp, dir))
+ try(Result.pcall(fs.sync.mkdirp, dir))
end
-- 2. Ensure source file exists and target doesn't yet exist OR if --force unlink target if it already
diff --git a/lua/mason-registry/sources/github.lua b/lua/mason-registry/sources/github.lua
index 7b650ae8..73c9d285 100644
--- a/lua/mason-registry/sources/github.lua
+++ b/lua/mason-registry/sources/github.lua
@@ -95,7 +95,7 @@ function GitHubRegistrySource:install()
if not fs.async.dir_exists(self.root_dir) then
log.debug("Creating registry directory", self)
- try(Result.pcall(fs.async.mkdirp, self.root_dir))
+ try(Result.pcall(fs.sync.mkdirp, self.root_dir))
end
if version == nil then
diff --git a/tests/mason-core/fs_spec.lua b/tests/mason-core/fs_spec.lua
index 9df22578..3962b8cd 100644
--- a/tests/mason-core/fs_spec.lua
+++ b/tests/mason-core/fs_spec.lua
@@ -18,4 +18,17 @@ describe("fs", function()
e
)
end)
+
+ it("should mkdirp", function()
+ local temp = vim.fn.tempname()
+ local nested = vim.fs.joinpath(temp, "nested", "directory", "here")
+
+ assert.has_error(function()
+ assert(vim.uv.fs_stat(nested))
+ end)
+
+ fs.sync.mkdirp(nested)
+ local stat = assert(vim.uv.fs_stat(nested), "fs_stat returned no value")
+ assert.equals("directory", stat.type)
+ end)
end)
diff --git a/tests/mason-core/installer/linker_spec.lua b/tests/mason-core/installer/linker_spec.lua
index 6bf63a14..f2835f34 100644
--- a/tests/mason-core/installer/linker_spec.lua
+++ b/tests/mason-core/installer/linker_spec.lua
@@ -110,7 +110,7 @@ describe("linker", function()
it("should symlink share files", function()
local ctx = test_helpers.create_context()
- stub(fs.async, "mkdirp")
+ stub(fs.sync, "mkdirp")
stub(fs.async, "dir_exists")
stub(fs.async, "file_exists")
stub(fs.async, "symlink")
@@ -142,8 +142,8 @@ describe("linker", function()
.spy(fs.async.symlink)
.was_called_with("../../../packages/dummy/nested/path/to/share-file", ctx.location:share "nested/path/share-file")
- assert.spy(fs.async.mkdirp).was_called(2)
- assert.spy(fs.async.mkdirp).was_called_with(ctx.location:share "nested/path")
+ assert.spy(fs.sync.mkdirp).was_called(2)
+ assert.spy(fs.sync.mkdirp).was_called_with(ctx.location:share "nested/path")
end)
it("should copy share files on Windows", function()
@@ -155,7 +155,7 @@ describe("linker", function()
platform.is.unix = false
platform.is.win = true
- stub(fs.async, "mkdirp")
+ stub(fs.sync, "mkdirp")
stub(fs.async, "dir_exists")
stub(fs.async, "file_exists")
stub(fs.async, "copy_file")
@@ -189,7 +189,7 @@ describe("linker", function()
{ excl = true }
)
- assert.spy(fs.async.mkdirp).was_called(2)
- assert.spy(fs.async.mkdirp).was_called_with(ctx.location:share "nested/path")
+ assert.spy(fs.sync.mkdirp).was_called(2)
+ assert.spy(fs.sync.mkdirp).was_called_with(ctx.location:share "nested/path")
end)
end)