Skip to content

Commit

Permalink
main. util: fix problems of readlink etc. found by test in macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Aug 24, 2022
1 parent f8aeb51 commit a1adc7f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ble.pp
Expand Up @@ -411,15 +411,23 @@ function ble/util/readlink/.readlink {
function ble/util/readlink/.resolve-physical-directory {
[[ $path == */?* ]] || return 0
local PWD=$PWD OLDPWD=$OLDPWD CDPATH=
builtin cd -L . &&
local pwd=$PWD &&
if builtin cd -L .; then
local pwd=$PWD
builtin cd -P "${path%/*}/" &&
path=${PWD%/}/${path##*/}
builtin cd -L "$pwd"
path=${PWD%/}/${path##*/}

# Note #D1849: 現在ディレクトリが他者により改名されている場合や PWD がユー
# ザーに書き換えられている場合にも元のディレクトリに戻る為、cd -L . した
# 後のパスに cd する。但し pwd の結果はこの関数の呼び出し前と変わってしま
# う (が実際にはこの方が良いだろう)。PWD は local にして元の値に戻すので
# 変わらない。
builtin cd "$pwd"
fi
return 0
}
function ble/util/readlink/.resolve-loop {
local path=$ret
while [[ $path == ?*/ ]]; do path=${path%/}; done
builtin eval -- "$_ble_util_readlink_visited_init"
while [[ -h $path ]]; do
local link
Expand All @@ -430,7 +438,7 @@ function ble/util/readlink/.resolve-loop {
else
# 相対パス ../ は物理ディレクトリ構造に従って遡る。
ble/util/readlink/.resolve-physical-directory
path=${path%/}/$link
path=${path%/*}/$link
fi
while [[ $path == ?*/ ]]; do path=${path%/}; done
done
Expand Down

0 comments on commit a1adc7f

Please sign in to comment.