Use the cache directory owner for cache entries

Commit f086bc9564 (Maintain ownership when rewriting universal variables
file, 2015-09-26) fixed an issue where "sudo -E fish" would create root-owned
~/.config/fish/fish_variables that break the users's shell.

A simlar issue exists for files in ~/.cache/fish; fix that.

Note that ~/.cache/fish is currently created on first run when we generate
completions from manpages.

See the issue described in #11292
This commit is contained in:
Johannes Altmanninger
2025-03-21 10:31:01 +01:00
parent 0dbfb4ccb1
commit 66115490d8
8 changed files with 20 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
function __fish_cache_put
set -l cache_file $argv[1]
touch $cache_file
set -l dir (path dirname $cache_file)
chown --reference=$dir $cache_file 2>/dev/null ||
chown (
stat --format '%u:%g' $dir 2>/dev/null ||
stat -f '%u:%g' $dir
) $cache_file
end