Skip to content

Commit

Permalink
fix(rpc)!: preseve files when stdio channel is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
zeertzjq committed Feb 6, 2023
1 parent 228684d commit 9d8f243
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/nvim/event/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,12 @@ static void exit_event(void **argv)
}

if (!exiting) {
os_exit(status);
if (ui_client_channel_id) {
os_exit(status);
} else {
assert(status == 0); // Called from rpc_close(), which passes 0 as status.
preserve_exit("Vim: stdio RPC channel closed\r\n");
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/nvim/msgpack_rpc/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ void rpc_close(Channel *channel)

if (channel->streamtype == kChannelStreamStdio
|| (channel->id == ui_client_channel_id && channel->streamtype != kChannelStreamProc)) {
if (channel->streamtype == kChannelStreamStdio) {
remote_ui_disconnect(channel->id);
}
exit_from_channel(0);
}
}
Expand Down
7 changes: 4 additions & 3 deletions test/functional/ex_cmds/swapfile_preserve_recover_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ local ok = helpers.ok
local rmdir = helpers.rmdir
local new_argv = helpers.new_argv
local pesc = helpers.pesc
local os_kill = helpers.os_kill
local set_session = helpers.set_session
local spawn = helpers.spawn
local nvim_async = helpers.nvim_async
Expand All @@ -39,8 +38,10 @@ end)

describe(':preserve', function()
local swapdir = lfs.currentdir()..'/Xtest_recover_dir'
local nvim1
before_each(function()
clear()
nvim1 = spawn(new_argv())
set_session(nvim1)
rmdir(swapdir)
lfs.mkdir(swapdir)
end)
Expand All @@ -67,7 +68,7 @@ describe(':preserve', function()

local swappath1 = eval('g:swapname')

os_kill(eval('getpid()'))
nvim1:close()
-- Start another Nvim instance.
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed'},
true)
Expand Down

0 comments on commit 9d8f243

Please sign in to comment.