feat: minor improved security measures

This commit is contained in:
Barrett Ruth 2026-03-07 19:05:43 -05:00
parent 27d7a4e6b5
commit d1b2117fa2
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
3 changed files with 29 additions and 11 deletions

View file

@ -56,8 +56,11 @@ function M.load()
end
if vim.fn.filereadable(cache_file) == 0 then
vim.fn.writefile({}, cache_file)
vim.fn.setfperm(cache_file, 'rw-------')
vim.fn.mkdir(vim.fn.fnamemodify(cache_file, ':h'), 'p')
local tmpfile = vim.fn.tempname()
vim.fn.writefile({}, tmpfile)
vim.fn.setfperm(tmpfile, 'rw-------')
vim.uv.fs_rename(tmpfile, cache_file)
loaded = true
return
end
@ -107,8 +110,10 @@ function M.save()
cache_data._version = CACHE_VERSION
local encoded = vim.json.encode(cache_data)
local lines = vim.split(encoded, '\n')
vim.fn.writefile(lines, cache_file)
vim.fn.setfperm(cache_file, 'rw-------')
local tmpfile = vim.fn.tempname()
vim.fn.writefile(lines, tmpfile)
vim.fn.setfperm(tmpfile, 'rw-------')
vim.uv.fs_rename(tmpfile, cache_file)
end)
end