fix: destroy the cache when VIMRUNTIME has changed

This commit is contained in:
Folke Lemaitre 2022-12-14 21:38:24 +01:00
parent 72f64ce1f7
commit 5128d896c7
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 12 additions and 1 deletions

View File

@ -155,6 +155,8 @@ end
function M.save_cache() function M.save_cache()
local f = assert(uv.fs_open(M.config.path, "w", 438)) local f = assert(uv.fs_open(M.config.path, "w", 438))
uv.fs_write(f, vim.env.VIMRUNTIME)
uv.fs_write(f, "\0")
for modname, entry in pairs(M.cache) do for modname, entry in pairs(M.cache) do
if entry.used > os.time() - M.ttl then if entry.used > os.time() - M.ttl then
entry.modname = modname entry.modname = modname
@ -184,7 +186,16 @@ function M.load_cache()
local data = uv.fs_read(f, cache_hash.size, 0) --[[@as string]] local data = uv.fs_read(f, cache_hash.size, 0) --[[@as string]]
uv.fs_close(f) uv.fs_close(f)
local offset = 1 local zero = data:find("\0", 1, true)
if not zero then
return
end
if vim.env.VIMRUNTIME ~= data:sub(1, zero - 1) then
return
end
local offset = zero + 1
while offset + 1 < #data do while offset + 1 < #data do
local header = ffi.cast("uint32_t*", ffi.new("const char[28]", data:sub(offset, offset + 27))) local header = ffi.cast("uint32_t*", ffi.new("const char[28]", data:sub(offset, offset + 27)))
offset = offset + 28 offset = offset + 28