mirror of
https://github.com/neovim/neovim.git
synced 2026-04-06 07:38:31 +00:00
fix(watch): invalid joined path #37973
Problem:
When vim._watch.watch() is used to watch a single file, libuv returns
the basename as the filename argument in the callback. The code joins
this with the watched path, producing a nonsensical path like
"/path/to/file.lua/file.lua", which causes ENOTDIR errors on
subsequent fs_stat calls.
Solution:
Check whether the watched path is a directory before joining the
filename. When watching a file, ignore the filename from libuv and
use the watched path directly.
(cherry picked from commit d9d8c660fd)
This commit is contained in:
committed by
github-actions[bot]
parent
de20500b40
commit
03815969c4
@@ -69,10 +69,12 @@ function M.watch(path, opts, callback)
|
||||
local uvflags = opts and opts.uvflags or {}
|
||||
local handle = assert(uv.new_fs_event())
|
||||
|
||||
local watching_dir = (uv.fs_stat(path) or {}).type == 'directory'
|
||||
|
||||
local _, start_err, start_errname = handle:start(path, uvflags, function(err, filename, events)
|
||||
assert(not err, err)
|
||||
local fullpath = path
|
||||
if filename then
|
||||
if filename and watching_dir then
|
||||
fullpath = vim.fs.normalize(vim.fs.joinpath(fullpath, filename))
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user