mirror of
https://github.com/neovim/neovim.git
synced 2026-04-06 07:38:31 +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.
(cherry picked from commit 6291256868)
This commit is contained in:
committed by
github-actions[bot]
parent
c7f48e40b8
commit
818b97173e
@@ -283,8 +283,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -224,9 +224,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)")
|
||||
@@ -247,7 +250,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