Browse Source

fix: add symlink check before calling readlink for uutils compatibility

The uutils/coreutils implementation of readlink emits error messages to
stderr when invoked on non-symlinks (regular files or directories):

  readlink: <file>: Invalid argument

By contrast, BSD and GNU readlink fail silently. This caused unwanted
error output when using jenv with uutils/coreutils.

The resolve_link() function is used in abs_dirname() to traverse paths,
and may be called on non-symlinks during normal operation. This fix adds
a symlink check using [ -L "$1" ] before invoking readlink, which:

- Prevents spurious error messages from uutils readlink
- Maintains compatibility with BSD, GNU, and uutils implementations
- Preserves real error visibility by only calling readlink on symlinks
- Avoids the need to suppress stderr which would hide genuine errors
pull/463/head
Kevin Burke 1 week ago
parent
commit
dc14008f31
No known key found for this signature in database
  1. 4
      libexec/jenv
  2. 4
      libexec/jenv-doctor
  3. 4
      libexec/jenv-hooks
  4. 4
      libexec/jenv-init
  5. 4
      libexec/jenv-plugins
  6. 4
      libexec/jenv-refresh-plugins
  7. 4
      libexec/jenv-refresh-versions

4
libexec/jenv

@ -3,7 +3,9 @@ set -e @@ -3,7 +3,9 @@ set -e
[ -n "$JENV_DEBUG" ] && set -x
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
if [ -L "$1" ]; then
$(type -p greadlink readlink | head -1) "$1"
fi
}
abs_dirname() {

4
libexec/jenv-doctor

@ -26,7 +26,9 @@ function cfix() { @@ -26,7 +26,9 @@ function cfix() {
}
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
if [ -L "$1" ]; then
$(type -p greadlink readlink | head -1) "$1"
fi
}
set -e

4
libexec/jenv-hooks

@ -25,7 +25,9 @@ if [ -z $shell ]; then @@ -25,7 +25,9 @@ if [ -z $shell ]; then
fi
resolve_link() {
$(type -p greadlink readlink | head -1) $1
if [ -L "$1" ]; then
$(type -p greadlink readlink | head -1) "$1"
fi
}
realpath() {

4
libexec/jenv-init

@ -30,7 +30,9 @@ if [ -z "$shell" ]; then @@ -30,7 +30,9 @@ if [ -z "$shell" ]; then
fi
resolve_link() {
$(type -p greadlink readlink | head -1) $1
if [ -L "$1" ]; then
$(type -p greadlink readlink | head -1) "$1"
fi
}
abs_dirname() {

4
libexec/jenv-plugins

@ -14,7 +14,9 @@ fi @@ -14,7 +14,9 @@ fi
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
if [ -L "$1" ]; then
$(type -p greadlink readlink | head -1) "$1"
fi
}
samedir() {

4
libexec/jenv-refresh-plugins

@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
# Summary: Refresh plugins links
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
if [ -L "$1" ]; then
$(type -p greadlink readlink | head -1) "$1"
fi
}
set -e

4
libexec/jenv-refresh-versions

@ -2,7 +2,9 @@ @@ -2,7 +2,9 @@
# Summary: Refresh alias names
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
if [ -L "$1" ]; then
$(type -p greadlink readlink | head -1) "$1"
fi
}
set -e

Loading…
Cancel
Save