mirror of
https://github.com/neovim/neovim.git
synced 2026-03-31 04:42:03 +00:00
fix(process): avoid buffering unnecessary UI event with PTY CWD (#37582)
Problem: Calling os_chdir() to change the child processes' CWD may cause some unnecessary UI events to be buffered. These UI events don't go anywhere as execvp() is called before flushing the UI buffer. Solution: Use uv_chdir() instead of os_chdir(). Also fix getting error string incorrectly. Add test for the current behavior.
This commit is contained in:
@@ -281,8 +281,10 @@ static void init_child(PtyProc *ptyproc)
|
||||
signal(SIGALRM, SIG_DFL);
|
||||
|
||||
Proc *proc = (Proc *)ptyproc;
|
||||
if (proc->cwd && os_chdir(proc->cwd) != 0) {
|
||||
ELOG("chdir(%s) failed: %s", proc->cwd, strerror(errno));
|
||||
int err = 0;
|
||||
// Don't use os_chdir() as that may buffer UI events unnecessarily.
|
||||
if (proc->cwd && (err = uv_chdir(proc->cwd)) != 0) {
|
||||
ELOG("chdir(%s) failed: %s", proc->cwd, uv_strerror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -246,9 +246,12 @@ describe('jobs', function()
|
||||
eq({ 'notification', 'exit', { 0, 0 } }, next_msg())
|
||||
end)
|
||||
|
||||
it('changes to given `cwd` directory', function()
|
||||
local function test_job_cwd()
|
||||
local dir = eval('resolve(tempname())'):gsub('/', get_pathsep())
|
||||
mkdir(dir)
|
||||
finally(function()
|
||||
rmdir(dir)
|
||||
end)
|
||||
command("let g:job_opts.cwd = '" .. dir .. "'")
|
||||
if is_os('win') then
|
||||
command("let j = jobstart('cd', g:job_opts)")
|
||||
@@ -269,7 +272,15 @@ describe('jobs', function()
|
||||
{ 'notification', 'exit', { 0, 0 } },
|
||||
}
|
||||
)
|
||||
rmdir(dir)
|
||||
end
|
||||
|
||||
it('changes to given `cwd` directory', function()
|
||||
test_job_cwd()
|
||||
end)
|
||||
|
||||
it('changes to given `cwd` directory with pty', function()
|
||||
command('let g:job_opts.pty = v:true')
|
||||
test_job_cwd()
|
||||
end)
|
||||
|
||||
it('fails to change to invalid `cwd`', function()
|
||||
|
||||
Reference in New Issue
Block a user