diff options
| author | William Boman <william@redwill.se> | 2021-10-30 16:36:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-30 16:36:21 +0200 |
| commit | e490ceed333670e0d3c516314f2ef1831a9f43a9 (patch) | |
| tree | 2277ead058e07dc9986590b4a55c58b2b819c603 /lua/nvim-lsp-installer/fs.lua | |
| parent | server: add :on_ready() method (#214) (diff) | |
| download | mason-e490ceed333670e0d3c516314f2ef1831a9f43a9.tar mason-e490ceed333670e0d3c516314f2ef1831a9f43a9.tar.gz mason-e490ceed333670e0d3c516314f2ef1831a9f43a9.tar.bz2 mason-e490ceed333670e0d3c516314f2ef1831a9f43a9.tar.lz mason-e490ceed333670e0d3c516314f2ef1831a9f43a9.tar.xz mason-e490ceed333670e0d3c516314f2ef1831a9f43a9.tar.zst mason-e490ceed333670e0d3c516314f2ef1831a9f43a9.zip | |
colocate tmpdir with the server's install dir to avoid cross-fs issues (#217)
Fixes #215.
Diffstat (limited to 'lua/nvim-lsp-installer/fs.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/fs.lua | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lua/nvim-lsp-installer/fs.lua b/lua/nvim-lsp-installer/fs.lua index 023d1db5..b6dce79d 100644 --- a/lua/nvim-lsp-installer/fs.lua +++ b/lua/nvim-lsp-installer/fs.lua @@ -5,13 +5,8 @@ local settings = require "nvim-lsp-installer.settings" local uv = vim.loop local M = {} -local tmpdir_root = vim.fn.fnamemodify(vim.fn.tempname(), ":h") - local function assert_ownership(path) - if - not pathm.is_subdirectory(settings.current.install_root_dir, path) - and not pathm.is_subdirectory(tmpdir_root, path) - then + if not pathm.is_subdirectory(settings.current.install_root_dir, path) then log.fmt_error("assert_ownership() failed on path %s", path) error( ("Refusing to operate on path (%s) outside of the servers root dir (%s)."):format( @@ -22,7 +17,7 @@ local function assert_ownership(path) end end ----@param path @The full path to the file/dir to recursively delete. Will refuse to operate on paths outside of the install_root dir setting. +---@param path string @The full path to the file/dir to recursively delete. Will refuse to operate on paths outside of the install_root dir setting. function M.rmrf(path) log.debug("fs: rmrf", path) assert_ownership(path) @@ -58,6 +53,15 @@ function M.mkdir(path) assert(uv.fs_mkdir(path, 493)) -- 493(10) == 755(8) end +---Recursively removes the path if it exists before creating a directory. +---@param path string @The full path to the directory to create. Will refuse to operate on paths outside of the install_root dir setting. +function M.rm_mkdirp(path) + if M.dir_exists(path) then + M.rmrf(path) + end + return M.mkdirp(path) +end + ---@param path string @The full path to check if it 1) exists, and 2) is a directory. ---@return boolean function M.dir_exists(path) |
