From 5128d896c759c0599b6da5f5ba2cee102d864cad Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 14 Dec 2022 21:38:24 +0100 Subject: [PATCH] fix: destroy the cache when VIMRUNTIME has changed --- lua/lazy/core/cache.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/lazy/core/cache.lua b/lua/lazy/core/cache.lua index 12d9394..8bcd203 100644 --- a/lua/lazy/core/cache.lua +++ b/lua/lazy/core/cache.lua @@ -155,6 +155,8 @@ end function M.save_cache() 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 if entry.used > os.time() - M.ttl then entry.modname = modname @@ -184,7 +186,16 @@ function M.load_cache() local data = uv.fs_read(f, cache_hash.size, 0) --[[@as string]] 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 local header = ffi.cast("uint32_t*", ffi.new("const char[28]", data:sub(offset, offset + 27))) offset = offset + 28