os: create the folder described by XDG_CACHE_HOME, *if it is non empty, and it does not exist yet*, when calling os.cache_dir() (#20046)

This commit is contained in:
gym603 2023-12-01 05:04:42 +08:00 committed by GitHub
parent 300158dd08
commit afaeb74238
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -733,6 +733,9 @@ pub fn cache_dir() string {
// or empty, a default equal to $HOME/.cache should be used. // or empty, a default equal to $HOME/.cache should be used.
xdg_cache_home := getenv('XDG_CACHE_HOME') xdg_cache_home := getenv('XDG_CACHE_HOME')
if xdg_cache_home != '' { if xdg_cache_home != '' {
if !is_dir(xdg_cache_home) && !is_link(xdg_cache_home) {
mkdir_all(xdg_cache_home, mode: 0o700) or { panic(err) }
}
return xdg_cache_home return xdg_cache_home
} }
cdir := join_path_single(home_dir(), '.cache') cdir := join_path_single(home_dir(), '.cache')