Skip to content

Commit 8275c52

Browse files
committed
fs-path.bash: fix follow validation on fedora
/ref 3cbcbce
1 parent 02ee255 commit 8275c52

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

commands/fs-path.bash

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,16 @@ function __process() (
137137
symlink_status=0
138138
if [[ $resolve == 'follow' ]]; then
139139
# resolve all symlinks (nested and recursive) and make absolute
140-
# `readlink ...` on a broken symlink (recursive or otherwise) / on a inaccessible target (recursive or otherwise)
140+
# `readlink ...` on a broken symlink (recursive or otherwise):
141+
# `-f` on macos will resolve with failure exit status
142+
# `-f` on fedora/GNU will resolve with success exit status
143+
# `-m` on fedora/GNU will resolve with readlsuccess exit status
144+
# `-e` on fedora/GNU will not resolve with failure exit status
145+
# `readlink ...` on a inaccessible target (recursive or otherwise)
141146
# `-f` on macos will resolve with failure exit status
142147
# `-f` on fedora/GNU will not resolve with failure exit status
143148
# `-m` on fedora/GNU will resolve with success exit status
149+
# `-e` on fedora/GNU will not resolve with failure exit status
144150
# macos only has `-f`, fedora/GNU has `-<f|e|m>`
145151
# so do `-f` which is macos and fedora, and if it is empty (fedora/GNU) then fill with `-m` but keep `-f`'s exit status
146152
resolution="$(readlink -f -- "$path")" || symlink_status=9
@@ -151,6 +157,9 @@ function __process() (
151157
if [[ -z $resolution ]]; then
152158
return 9 # EBADF 9 Bad file descriptor
153159
fi
160+
elif [[ $symlink_status -eq 0 ]] && ! readlink -e -- "$path"; then
161+
# broken symlink on fedora/GNU; this will never be reached on macos, as on macos `readlink -f` always resolves
162+
symlink_status=9 # EBADF 9 Bad file descriptor
154163
fi
155164
# check resolution, is fine that it runs on the pre-resolution old path, as long as it is absolute
156165
if [[ $symlink_status -ne 0 ]]; then
@@ -184,6 +193,7 @@ function __process() (
184193
# reiterate on the resolved path, without further resolutions, to resolve synthetics and relatives, and validation
185194
# can't do validation earlier, as `[[ -<...> ]]` behave differently on synthetic and relative paths within a symlink dir, see earlier note
186195
if_missing_it_is_because_of_symlink='yes'
196+
# @for with the current <validate> functionality, it behaves akin to `--follow --validate`, so we perhaps could avoid a lot of drama by just doing a `readlink -e` check regardless of resolution method, however `readlink -e` is not available on macos, and eventually @todo we may want `--resolve --validate` to only validate the first resolution and not all - but for now, `--validate` essentially implies `--follow`
187197
if [[ ${resolution:0:1} == '/' ]]; then
188198
# absolute, replace
189199
path="$resolution"

0 commit comments

Comments
 (0)