diff --git a/ble.pp b/ble.pp index 05dce70d..06e56874 100644 --- a/ble.pp +++ b/ble.pp @@ -1589,11 +1589,15 @@ function ble/base/initialize-base-directory { ## 2. /tmp/blesh/$UID を作成可能ならば、それを使う。 ## 3. $_ble_base/tmp/$UID を使う。 ## +_ble_base_is_wsl_status= function ble/base/initialize-runtime-directory/.is-wsl { + [[ $_ble_base_is_wsl_status ]] && return "$_ble_base_is_wsl_status" + _ble_base_is_wsl_status=1 [[ -d /usr/lib/wsl/lib && -r /proc/version ]] || return 1 local kernel_version ble/bash/read kernel_version < /proc/version || return 1 - [[ $kernel_version == *-microsoft-* ]] + [[ $kernel_version == *-microsoft-* ]] || return 1 + _ble_base_is_wsl_status=0 } function ble/base/initialize-runtime-directory/.xdg { local runtime_dir= @@ -1633,6 +1637,12 @@ function ble/base/initialize-runtime-directory/.xdg { function ble/base/initialize-runtime-directory/.tmp { [[ -r /tmp && -w /tmp && -x /tmp ]] || return 1 + # Note: WSL seems to clear /tmp after the first instance of Bash starts, + # which causes a problem of missing /tmp after blesh's initialization. + # https://github.com/microsoft/WSL/issues/8441#issuecomment-1139434972 + # https://github.com/akinomyoga/ble.sh/discussions/462 + ble/base/initialize-runtime-directory/.is-wsl && return 1 + local tmp_dir=/tmp/blesh if [[ ! -d $tmp_dir ]]; then [[ ! -e $tmp_dir && -h $tmp_dir ]] && ble/bin/rm -f "$tmp_dir" @@ -1649,11 +1659,7 @@ function ble/base/initialize-runtime-directory/.tmp { ble/base/.create-user-directory _ble_base_run "$tmp_dir/$UID" } -function ble/base/initialize-runtime-directory { - ble/base/initialize-runtime-directory/.xdg && return 0 - ble/base/initialize-runtime-directory/.tmp && return 0 - - # fallback +function ble/base/initialize-runtime-directory/.base { local tmp_dir=$_ble_base/run if [[ ! -d $tmp_dir ]]; then ble/bin/mkdir -p "$tmp_dir" || return 1 @@ -1661,6 +1667,32 @@ function ble/base/initialize-runtime-directory { fi ble/base/.create-user-directory _ble_base_run "$tmp_dir/${USER:-$UID}@$HOSTNAME" } +function ble/base/initialize-runtime-directory/.home { + local cache_dir=${XDG_CACHE_HOME:-$HOME/.cache} + if [[ ! -d $cache_dir ]]; then + if [[ $XDG_CACHE_HOME ]]; then + ble/util/print "ble.sh: XDG_CACHE_HOME='$XDG_CACHE_HOME' is not a directory." >&2 + return 1 + else + ble/bin/mkdir -p "$cache_dir" || return 1 + fi + fi + if ! [[ -r $cache_dir && -w $cache_dir && -x $cache_dir ]]; then + if [[ $XDG_CACHE_HOME ]]; then + ble/util/print "ble.sh: XDG_CACHE_HOME='$XDG_CACHE_HOME' doesn't have a proper permission." >&2 + else + ble/util/print "ble.sh: '$cache_dir' doesn't have a proper permission." >&2 + fi + return 1 + fi + ble/base/.create-user-directory _ble_base_run "$cache_dir/blesh/run" +} +function ble/base/initialize-runtime-directory { + ble/base/initialize-runtime-directory/.xdg && return 0 + ble/base/initialize-runtime-directory/.tmp && return 0 + ble/base/initialize-runtime-directory/.base && return 0 + ble/base/initialize-runtime-directory/.home +} if ! ble/base/initialize-runtime-directory; then ble/util/print "ble.sh: failed to initialize \$_ble_base_run." >&2 ble/base/clear-version-variables diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 083f014f..0c284d1e 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -158,6 +158,7 @@ - term: detect iTerm2 `#D2224` xxxxxxxx - mandb: support man page format of `rg` (requested by pallaswept) `#D2225` xxxxxxxx - mandb: restore ASCII hyphens from Unicode hyphens before analysis (reported by pallaswept) `#D2230` xxxxxxxx +- main: work around the issue WSL clears `/tmp` after Bash starts (reported by LeonardoMor) `#D2235` xxxxxxxx ## Contrib diff --git a/note.txt b/note.txt index 3d38b605..44f01f47 100644 --- a/note.txt +++ b/note.txt @@ -7394,6 +7394,14 @@ bash_tips 2024-07-01 + * main: work around the issue that WSL clears "/tmp" after Bash starts (reported by LeonardoMor) [#D2235] + https://github.com/akinomyoga/ble.sh/discussions/462 + https://github.com/microsoft/WSL/issues/8441#issuecomment-1139434972 + + 既に WSL で報告されている様だ。gitstatus が /tmp を作った後に中身が消去され + ているという問題。報告されていて romkatv は何度も mention しているが、WSL + での issue は閉じられて無視されている。 + * test: skip tests on "ble/test/chdir" failure [#D2234] 何らかの理由で ble/test/chdir に失敗した時 (例えば permission の問題でディ