浏览代码

fix(core): use `$HOME/.cache` if default cache dir is non-writable (#10193)

Fixes #10193
Marc Cornellà 2 年之前
父节点
当前提交
8784e88552
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      oh-my-zsh.sh

+ 6 - 1
oh-my-zsh.sh

@@ -7,7 +7,12 @@ if [[ -z "$ZSH_CACHE_DIR" ]]; then
   ZSH_CACHE_DIR="$ZSH/cache"
 fi
 
-# Create completions cache dir and add to $fpath
+# Make sure $ZSH_CACHE_DIR is writable, otherwise use a directory in $HOME
+if [[ ! -w "$ZSH_CACHE_DIR" ]]; then
+  ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/ohmyzsh"
+fi
+
+# Create cache and completions dir and add to $fpath
 mkdir -p "$ZSH_CACHE_DIR/completions"
 (( ${fpath[(Ie)$ZSH_CACHE_DIR/completions]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)