diff options
Diffstat (limited to '')
| -rw-r--r-- | .config/yay/hooks/maintainer_change.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/.config/yay/hooks/maintainer_change.lua b/.config/yay/hooks/maintainer_change.lua new file mode 100644 index 0000000..9f8be2d --- /dev/null +++ b/.config/yay/hooks/maintainer_change.lua | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | -- Copypasted from https://github.com/Jguer/yay/blob/next/doc/examples/maintainer_change.lua | ||
| 2 | -- | ||
| 3 | -- Warn when an AUR package's maintainer changes between upgrades. | ||
| 4 | -- | ||
| 5 | -- The known maintainer for each package is stored in a plain text cache file | ||
| 6 | -- inside the yay cache directory (build_dir). On the first upgrade for a | ||
| 7 | -- package the current maintainer is recorded without any warning. On | ||
| 8 | -- subsequent upgrades: | ||
| 9 | -- * same maintainer → debug "match correct" | ||
| 10 | -- * different maintainer → error "new maintainer, double check build files" | ||
| 11 | -- | ||
| 12 | -- The cache is updated whenever a new or changed maintainer is seen. | ||
| 13 | -- | ||
| 14 | -- Cache file location: <cache_dir>/maintainer_cache | ||
| 15 | -- Format: one "pkgname=maintainer" entry per line. | ||
| 16 | |||
| 17 | -- missing reliable cfg getter | ||
| 18 | local cache_dir = (os.getenv("XDG_CACHE_HOME") or (os.getenv("HOME") .. "/.cache")) .. "/yay" | ||
| 19 | local cache_file = cache_dir .. "/maintainer_cache" | ||
| 20 | |||
| 21 | local function load_cache() | ||
| 22 | local cache = {} | ||
| 23 | local f = io.open(cache_file, "r") | ||
| 24 | if not f then return cache end | ||
| 25 | for line in f:lines() do | ||
| 26 | local name, maintainer = line:match("^([^=]+)=(.*)$") | ||
| 27 | if name then | ||
| 28 | cache[name] = maintainer | ||
| 29 | end | ||
| 30 | end | ||
| 31 | f:close() | ||
| 32 | return cache | ||
| 33 | end | ||
| 34 | |||
| 35 | local function save_cache(cache) | ||
| 36 | local f = assert(io.open(cache_file, "w")) | ||
| 37 | for name, maintainer in pairs(cache) do | ||
| 38 | f:write(name .. "=" .. maintainer .. "\n") | ||
| 39 | end | ||
| 40 | f:close() | ||
| 41 | end | ||
| 42 | |||
| 43 | yay.create_autocmd("UpgradeSelect", { | ||
| 44 | desc = "warn on AUR maintainer changes", | ||
| 45 | callback = function(event) | ||
| 46 | yay.log.info("checking for AUR maintainer changes") | ||
| 47 | local cache = load_cache() | ||
| 48 | local dirty = false | ||
| 49 | |||
| 50 | for _, pkg in ipairs(event.data.upgrades) do | ||
| 51 | if pkg.repository == "aur" and pkg.maintainer ~= "" then | ||
| 52 | local cached = cache[pkg.name] | ||
| 53 | if cached == nil then | ||
| 54 | -- First time seeing this package: seed the cache silently. | ||
| 55 | cache[pkg.name] = pkg.maintainer | ||
| 56 | dirty = true | ||
| 57 | elseif cached == pkg.maintainer then | ||
| 58 | yay.log.debug("match correct: " .. pkg.name .. " " .. pkg.maintainer) | ||
| 59 | else | ||
| 60 | yay.log.error("new maintainer, double check build files: ", pkg.name, | ||
| 61 | "(was: " .. cached .. ", now: " .. pkg.maintainer .. ")") | ||
| 62 | cache[pkg.name] = pkg.maintainer | ||
| 63 | dirty = true | ||
| 64 | end | ||
| 65 | end | ||
| 66 | end | ||
| 67 | |||
| 68 | if dirty then | ||
| 69 | yay.log.info("saving maintainer cache:", cache_file) | ||
| 70 | save_cache(cache) | ||
| 71 | end | ||
| 72 | |||
| 73 | return { exclude = {}, skip_menu = false } | ||
| 74 | end, | ||
| 75 | }) | ||
