Skip to content

Commit 91fd4d1

Browse files
shmerlgithub-actions[bot]
authored andcommitted
fix(vim.loader): randomized AppImage path pollutes luac cache #35636
Problem: When using the Nvim appimage, `~/.cache/nvim/luac` directory can grow to 250,000+ files. Example of 2 identical files in `./luac/`: %2ftmp%2f.mount_nvim.a65Rja0%2fusr%2fshare%2fnvim%2fruntime%2flua%2fvim%2ftreesitter.luac %2ftmp%2f.mount_nvim.aNpxXgo%2fusr%2fshare%2fnvim%2fruntime%2flua%2fvim%2ftreesitter.luac Analysis: The `nvim.appimage` mounts nvim at a different temporary path each time it is invoked. The naming scheme of these cache files is random, which defats the purpose of the cache creates N new files on every launch of nvim. Steps to reproduce: 1. install `nvim.appimage` 2. `mv ~/.cache/nvim/luac ~/.cache/nvim/luac.backup` 3. `nvim` 4. Observe contents of `~/.cache/nvim/luac/` 5. Close nvim and run `nvim` again 6. Observe contents of `~/.cache/nvim/luac/` and see that new identical files have been added with a different mount prefix Solution: When running from an appimage, trim the random part of the filepaths. (cherry picked from commit 78bbe53)
1 parent 83c589d commit 91fd4d1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

runtime/lua/vim/loader.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local loaders = package.loaders
77
local _loadfile = loadfile
88

99
local VERSION = 4
10+
local is_appimage = (os.getenv('APPIMAGE') ~= nil)
1011

1112
local M = {}
1213

@@ -78,7 +79,15 @@ local function fs_stat_cached(path)
7879
end
7980

8081
local function normalize(path)
81-
return fs.normalize(path, { expand_env = false, _fast = true })
82+
path = fs.normalize(path, { expand_env = false, _fast = true })
83+
84+
if is_appimage then
85+
-- Avoid cache pollution caused by AppImage randomizing the program root. #31165
86+
-- "/tmp/.mount_nvimAmpHPH/usr/share/nvim/runtime" => "/usr/share/nvim/runtime"
87+
path = path:match('(/usr/.*)') or path
88+
end
89+
90+
return path
8291
end
8392

8493
local rtp_cached = {} --- @type string[]

0 commit comments

Comments
 (0)