mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
shada: Fix non-writeable ShaDa directory handling
Before this change, nvim -i /etc/shada segfaults on exit if the file does not exist and user does not have permissions to create the file at /etc/shada. Closes #5296 Reported in #5277 https://github.com/neovim/neovim/issues/5277#issuecomment-243937255
This commit is contained in:
parent
cd321b7d0f
commit
6127eaef05
@ -2976,7 +2976,7 @@ shada_write_file_nomerge: {}
|
||||
if (sd_writer.cookie == NULL) {
|
||||
xfree(fname);
|
||||
xfree(tempname);
|
||||
if (sd_reader.close != NULL) {
|
||||
if (sd_reader.cookie != NULL) {
|
||||
sd_reader.close(&sd_reader);
|
||||
}
|
||||
return FAIL;
|
||||
|
@ -8,8 +8,8 @@ local mpack = require('mpack')
|
||||
local tmpname = helpers.tmpname()
|
||||
local additional_cmd = ''
|
||||
|
||||
local function nvim_argv()
|
||||
local argv = {nvim_prog, '-u', 'NONE', '-i', tmpname, '-N',
|
||||
local function nvim_argv(shada_file)
|
||||
local argv = {nvim_prog, '-u', 'NONE', '-i', shada_file or tmpname, '-N',
|
||||
'--cmd', 'set shortmess+=I background=light noswapfile',
|
||||
'--cmd', additional_cmd,
|
||||
'--embed'}
|
||||
@ -20,8 +20,8 @@ local function nvim_argv()
|
||||
end
|
||||
end
|
||||
|
||||
local reset = function()
|
||||
set_session(spawn(nvim_argv()))
|
||||
local reset = function(shada_file)
|
||||
set_session(spawn(nvim_argv(shada_file)))
|
||||
meths.set_var('tmpname', tmpname)
|
||||
end
|
||||
|
||||
|
@ -5,6 +5,7 @@ local meths, nvim_command, funcs, eq =
|
||||
local write_file, spawn, set_session, nvim_prog, exc_exec =
|
||||
helpers.write_file, helpers.spawn, helpers.set_session, helpers.nvim_prog,
|
||||
helpers.exc_exec
|
||||
|
||||
local lfs = require('lfs')
|
||||
local paths = require('test.config.paths')
|
||||
|
||||
@ -14,10 +15,14 @@ local shada_helpers = require('test.functional.shada.helpers')
|
||||
local reset, clear, get_shada_rw =
|
||||
shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw
|
||||
local read_shada_file = shada_helpers.read_shada_file
|
||||
local set_additional_cmd = shada_helpers.set_additional_cmd
|
||||
|
||||
local wshada, _, shada_fname, clean =
|
||||
get_shada_rw('Xtest-functional-shada-shada.shada')
|
||||
|
||||
local dirname = 'Xtest-functional-shada-shada.d'
|
||||
local dirshada = dirname .. '/main.shada'
|
||||
|
||||
if helpers.pending_win32(pending) then return end
|
||||
|
||||
describe('ShaDa support code', function()
|
||||
@ -25,6 +30,7 @@ describe('ShaDa support code', function()
|
||||
after_each(function()
|
||||
clear()
|
||||
clean()
|
||||
lfs.rmdir(dirname)
|
||||
end)
|
||||
|
||||
it('preserves `s` item size limit with unknown entries', function()
|
||||
@ -232,4 +238,17 @@ describe('ShaDa support code', function()
|
||||
eq('', meths.get_option('viminfo'))
|
||||
eq('', meths.get_option('shada'))
|
||||
end)
|
||||
|
||||
it('does not crash when ShaDa file directory is not writable', function()
|
||||
funcs.mkdir(dirname, '', 0)
|
||||
eq(0, funcs.filewritable(dirname))
|
||||
set_additional_cmd('set shada=')
|
||||
reset(dirshada)
|
||||
meths.set_option('shada', '\'10')
|
||||
eq('Vim(wshada):E886: System error while opening ShaDa file '
|
||||
.. 'Xtest-functional-shada-shada.d/main.shada for reading to merge '
|
||||
.. 'before writing it: permission denied',
|
||||
exc_exec('wshada'))
|
||||
meths.set_option('shada', '')
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user