diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-09-21 16:23:00 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-09-22 15:05:24 +0100 |
commit | 511b991e66892b4bb8176ce64c0e8fefb300f638 (patch) | |
tree | af0524ac4a781c0e719d056502be19983403cb01 /test | |
parent | 29bceb4f758097cc6b66726f1dcd3967ad170e35 (diff) | |
download | rneovim-511b991e66892b4bb8176ce64c0e8fefb300f638.tar.gz rneovim-511b991e66892b4bb8176ce64c0e8fefb300f638.tar.bz2 rneovim-511b991e66892b4bb8176ce64c0e8fefb300f638.zip |
feat(fs.lua): add vim.fs.rm()
Analogous to the shell `rm` command.
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/testnvim.lua | 43 |
1 files changed, 3 insertions, 40 deletions
diff --git a/test/functional/testnvim.lua b/test/functional/testnvim.lua index 36e6b4d7bd..8a2281e2a1 100644 --- a/test/functional/testnvim.lua +++ b/test/functional/testnvim.lua @@ -759,58 +759,21 @@ function M.assert_visible(bufnr, visible) end end ---- @param path string -local function do_rmdir(path) - local stat = uv.fs_stat(path) - if stat == nil then - return - end - if stat.type ~= 'directory' then - error(string.format('rmdir: not a directory: %s', path)) - end - for file in vim.fs.dir(path) do - if file ~= '.' and file ~= '..' then - local abspath = path .. '/' .. file - if t.isdir(abspath) then - do_rmdir(abspath) -- recurse - else - local ret, err = os.remove(abspath) - if not ret then - if not session then - error('os.remove: ' .. err) - else - -- Try Nvim delete(): it handles `readonly` attribute on Windows, - -- and avoids Lua cross-version/platform incompatibilities. - if -1 == M.call('delete', abspath) then - local hint = (is_os('win') and ' (hint: try :%bwipeout! before rmdir())' or '') - error('delete() failed' .. hint .. ': ' .. abspath) - end - end - end - end - end - end - local ret, err = uv.fs_rmdir(path) - if not ret then - error('luv.fs_rmdir(' .. path .. '): ' .. err) - end -end - local start_dir = uv.cwd() function M.rmdir(path) - local ret, _ = pcall(do_rmdir, path) + local ret, _ = pcall(vim.fs.rm, path, { recursive = true, force = true }) if not ret and is_os('win') then -- Maybe "Permission denied"; try again after changing the nvim -- process to the top-level directory. M.command([[exe 'cd '.fnameescape(']] .. start_dir .. "')") - ret, _ = pcall(do_rmdir, path) + ret, _ = pcall(vim.fs.rm, path, { recursive = true, force = true }) end -- During teardown, the nvim process may not exit quickly enough, then rmdir() -- will fail (on Windows). if not ret then -- Try again. sleep(1000) - do_rmdir(path) + vim.fs.rm(path, { recursive = true, force = true }) end end |