Skip to content

Commit

Permalink
dorothy, fs-realpath: detect when alpine uses busybox or coreutils an…
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Oct 15, 2024
1 parent 99ac325 commit a9a57f5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
18 changes: 11 additions & 7 deletions commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function dorothy_() (

# see [commands/is-alpine] for details
function __is_alpine {
test -f /etc/os-release && grep --quiet --ignore-case --regexp='ID=alpine' /etc/os-release 2>/dev/null;
test -f /etc/os-release && grep --quiet --ignore-case --regexp='ID=alpine' /etc/os-release 2>/dev/null
}

# see [commands/fs-realpath] for details
Expand Down Expand Up @@ -362,9 +362,11 @@ function dorothy_() (
if __command_exists -- grealpath; then
gnu_realpath='grealpath'
elif __command_exists -- realpath; then
if __is_mac || __is_alpine; then
# realpath on macos and alpine doesn't support any options, so missing --canonicalize-existing and --canonicalize-missing
# https://github.com/bevry/dorothy/actions/runs/11337594338/job/31529440618#step:4:36
if __is_mac; then
# usage: realpath [-q] [path ...]
fallback_realpath='realpath'
elif __is_alpine && test "$(realpath "$(type -P 'realpath')" || :)" = "$(type -P busybox || :)"; then
# Usage: realpath FILE...
fallback_realpath='realpath'
elif __is_linux; then
gnu_realpath='realpath'
Expand All @@ -373,9 +375,11 @@ function dorothy_() (
if __command_exists -- greadlink; then
gnu_readlink='greadlink'
elif __command_exists -- readlink; then
if __is_mac || __is_alpine; then
# readlink on macos and alpine doesn't support usual options, so missing --canonicalize-existing and --canonicalize-missing
# https://github.com/bevry/dorothy/actions/runs/11337683504/job/31529682952#step:4:36
if __is_mac; then
# usage: readlink [-fn] [file ...]
fallback_readlink='readlink'
elif __is_alpine && test "$(readlink -f "$(type -P 'readlink')" || :)" = "$(type -P busybox || :)"; then
# Usage: readlink [-fnv] FILE
fallback_readlink='readlink'
elif __is_linux; then
gnu_readlink='readlink'
Expand Down
59 changes: 38 additions & 21 deletions commands/fs-realpath
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,18 @@ function fs_realpath() (
local gnu_realpath
if __command_exists -- grealpath; then
gnu_realpath='grealpath'
elif __command_exists -- realpath && is-linux && ! is-alpine; then
# alpine realpath doesn't support any options, so missing --canonicalize-existing and --canonicalize-missing
# https://github.com/bevry/dorothy/actions/runs/11337594338/job/31529440618#step:4:36
# / # realpath --help
# BusyBox v1.36.1 (2024-06-10 07:11:47 UTC) multi-call binary.
# Usage: realpath FILE...
# Print absolute pathnames of FILEs
gnu_realpath='realpath'
elif __command_exists -- realpath; then
if is-mac; then
# usage: realpath [-q] [path ...]
return 45 # ENOTSUP 45 Operation not supported
elif is-alpine && test "$(realpath "$(type -P 'realpath')" || :)" = "$(type -P busybox || :)"; then
# Usage: realpath FILE...
return 45 # ENOTSUP 45 Operation not supported
elif is-linux; then
gnu_realpath='realpath'
else
return 45 # ENOTSUP 45 Operation not supported
fi
else
return 45 # ENOTSUP 45 Operation not supported
fi
Expand Down Expand Up @@ -148,17 +152,18 @@ function fs_realpath() (
local gnu_readlink
if __command_exists -- greadlink; then
gnu_readlink='greadlink'
elif __command_exists -- readlink && is-linux && ! is-alpine; then
# alpine readlink doesn't support any options, so missing --canonicalize-existing and --canonicalize-missing
# https://github.com/bevry/dorothy/actions/runs/11337683504/job/31529682952#step:4:36
# / # readlink --help
# BusyBox v1.36.1 (2024-06-10 07:11:47 UTC) multi-call binary.
# Usage: readlink [-fnv] FILE
# Display the value of a symlink
# -f Canonicalize by following all symlinks
# -n Don't add newline
# -v Verbose
gnu_readlink='readlink'
elif __command_exists -- readlink; then
if is-mac; then
# usage: readlink [-fn] [file ...]
return 45 # ENOTSUP 45 Operation not supported
elif is-alpine && test "$(readlink -f "$(type -P 'readlink')" || :)" = "$(type -P busybox || :)"; then
# Usage: readlink [-fnv] FILE
return 45 # ENOTSUP 45 Operation not supported
elif is-linux; then
gnu_readlink='readlink'
else
return 45 # ENOTSUP 45 Operation not supported
fi
else
return 45 # ENOTSUP 45 Operation not supported
fi
Expand Down Expand Up @@ -207,8 +212,14 @@ function fs_realpath() (

local fallback_readlink
if __command_exists -- readlink; then
if is-mac || is-alpine; then
if is-mac; then
# usage: readlink [-fn] [file ...]
fallback_readlink='readlink'
elif is-alpine && test "$(readlink -f "$(type -P 'readlink')" || :)" = "$(type -P busybox || :)"; then
# Usage: readlink [-fnv] FILE
fallback_readlink='readlink'
else
return 45 # ENOTSUP 45 Operation not supported
fi
else
return 45 # ENOTSUP 45 Operation not supported
Expand Down Expand Up @@ -243,8 +254,14 @@ function fs_realpath() (

local fallback_realpath
if __command_exists -- realpath; then
if is-mac || is-alpine; then
if is-mac; then
# usage: realpath [-q] [path ...]
fallback_realpath='realpath'
elif is-alpine && test "$(realpath "$(type -P 'realpath')" || :)" = "$(type -P busybox || :)"; then
# Usage: realpath FILE...
fallback_realpath='realpath'
else
return 45 # ENOTSUP 45 Operation not supported
fi
else
return 45 # ENOTSUP 45 Operation not supported
Expand Down

0 comments on commit a9a57f5

Please sign in to comment.