mirror of
https://github.com/neovim/neovim.git
synced 2026-05-06 16:29:57 -04:00
32aee065a8
Problem: If NVIM_LOG_FILE, or the default fallback, is inaccessible (e.g. directory is owned by root), users get confused. Solution: Show a warning when $NVIM_LOG_FILE or $XDG_STATE_HOME are inaccessible. Also fix a latent memory leak: `os_mkdir_recurse` returns a uv error code (int), but it was stored as `bool`, causing `os_strerror` to receive an invalid error code and leak memory. See: https://docs.libuv.org/en/v1.x/errors.html#c.uv_strerror Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
31 lines
702 B
Lua
31 lines
702 B
Lua
local M = {}
|
|
|
|
--- Checks that the logfile is accessible.
|
|
function M.check_log_file()
|
|
if vim.fn.mode() == 'c' then -- Ex mode
|
|
return
|
|
end
|
|
|
|
local wanted = vim.fn.getenv('__NVIM_LOG_FILE_WANT')
|
|
if not wanted or wanted == vim.NIL then
|
|
return
|
|
end
|
|
|
|
local actual = vim.fn.getenv('NVIM_LOG_FILE')
|
|
|
|
local msg --[[@type string]]
|
|
if not actual or actual == vim.NIL or actual == '' then
|
|
msg = ('log: %q not accessible, logging disabled (stderr)'):format(wanted)
|
|
elseif actual ~= wanted then
|
|
msg = ('log: %q not accessible, logging to: %q'):format(wanted, actual)
|
|
else
|
|
return
|
|
end
|
|
|
|
vim.defer_fn(function()
|
|
vim.notify(msg, vim.log.levels.WARN)
|
|
end, 100)
|
|
end
|
|
|
|
return M
|