diff options
| author | William Boman <william@redwill.se> | 2021-08-15 02:09:50 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2021-08-15 02:51:33 +0200 |
| commit | 88a2a8557a92e69e683452e53a87b02b5d924412 (patch) | |
| tree | bd5314e4487be78c347e0cab41ef82bb65de7d8d /lua/nvim-lsp-installer/fs.lua | |
| parent | fs: use native vim.fns (diff) | |
| download | mason-88a2a8557a92e69e683452e53a87b02b5d924412.tar mason-88a2a8557a92e69e683452e53a87b02b5d924412.tar.gz mason-88a2a8557a92e69e683452e53a87b02b5d924412.tar.bz2 mason-88a2a8557a92e69e683452e53a87b02b5d924412.tar.lz mason-88a2a8557a92e69e683452e53a87b02b5d924412.tar.xz mason-88a2a8557a92e69e683452e53a87b02b5d924412.tar.zst mason-88a2a8557a92e69e683452e53a87b02b5d924412.zip | |
fs: assert unsafe operations are run on safe paths only
Diffstat (limited to 'lua/nvim-lsp-installer/fs.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/fs.lua | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lua/nvim-lsp-installer/fs.lua b/lua/nvim-lsp-installer/fs.lua index 55809767..0cfaceca 100644 --- a/lua/nvim-lsp-installer/fs.lua +++ b/lua/nvim-lsp-installer/fs.lua @@ -1,7 +1,23 @@ +local pathm = require("nvim-lsp-installer.path") + local uv = vim.loop local M = {} +local function assert_ownership(path) + if not pathm.is_subdirectory(pathm.SERVERS_ROOT_DIR, path) then + error(("Refusing to operate on path outside of the servers root dir (%s)."):format(pathm.SERVERS_ROOT_DIR)) + end +end + +function M.rmrf(path) + assert_ownership(path) + if vim.fn.delete(path, "rf") ~= 0 then + error(("rmrf: Could not remove directory %q."):format(path)) + end +end + function M.mkdirp(path) + assert_ownership(path) if vim.fn.mkdir(path, "p") ~= 1 then error(("mkdirp: Could not create directory %q."):format(path)) end @@ -28,10 +44,4 @@ function M.fstat(path) return assert(uv.fs_fstat(fd)) end -function M.rmrf(path) - if vim.fn.delete(path, "rf") ~= 0 then - error(("rmrf: Could not remove directory %q."):format(path)) - end -end - return M |
