[Fix] nvm_ls: treat a version dir with only hidden entries as empty
`nvm_ls` decides whether a version dir is worth searching with `ls -1qA`, which
also counts dotfiles, but then collects versions with `find "${DIR}"/*`, which
never matches them. A dir holding nothing but hidden entries passes the guard,
so when `nullglob` is not set `find` is handed the literal `*` and `nvm ls`
prints "No such file or directory" to stderr.
Drop `-A` from the guard so both halves agree on what counts as an entry.
Fixes #3727.
This commit is contained in:
1 parent
c6bf252f7d
commit
c8dc8c9b1c
2 files changed
+42
-3
No files matched your search
@@ -2487,13 +2487,13 @@ nvm_ls() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -d "${NVM_DIRS_TO_SEARCH1}" ] || ! (command ls -1qA "${NVM_DIRS_TO_SEARCH1}" | nvm_grep -q .); then
|
if ! [ -d "${NVM_DIRS_TO_SEARCH1}" ] || ! (command ls -1q "${NVM_DIRS_TO_SEARCH1}" | nvm_grep -q .); then
|
||||||
NVM_DIRS_TO_SEARCH1=''
|
NVM_DIRS_TO_SEARCH1=''
|
||||||
fi
|
fi
|
||||||
if ! [ -d "${NVM_DIRS_TO_SEARCH2}" ] || ! (command ls -1qA "${NVM_DIRS_TO_SEARCH2}" | nvm_grep -q .); then
|
if ! [ -d "${NVM_DIRS_TO_SEARCH2}" ] || ! (command ls -1q "${NVM_DIRS_TO_SEARCH2}" | nvm_grep -q .); then
|
||||||
NVM_DIRS_TO_SEARCH2="${NVM_DIRS_TO_SEARCH1}"
|
NVM_DIRS_TO_SEARCH2="${NVM_DIRS_TO_SEARCH1}"
|
||||||
fi
|
fi
|
||||||
if ! [ -d "${NVM_DIRS_TO_SEARCH3}" ] || ! (command ls -1qA "${NVM_DIRS_TO_SEARCH3}" | nvm_grep -q .); then
|
if ! [ -d "${NVM_DIRS_TO_SEARCH3}" ] || ! (command ls -1q "${NVM_DIRS_TO_SEARCH3}" | nvm_grep -q .); then
|
||||||
NVM_DIRS_TO_SEARCH3="${NVM_DIRS_TO_SEARCH2}"
|
NVM_DIRS_TO_SEARCH3="${NVM_DIRS_TO_SEARCH2}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
[ -n "${NVM_DIR-}" ] && [ -d "${NVM_DIR}" ] && rm -rf "${NVM_DIR}"
|
||||||
|
unset -f die cleanup
|
||||||
|
unset NVM_DIR
|
||||||
|
}
|
||||||
|
|
||||||
|
die() { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
|
: nvm.sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
NVM_DIR="$(mktemp -d)"
|
||||||
|
[ -n "${NVM_DIR}" ] || die 'unable to create temp NVM_DIR'
|
||||||
|
|
||||||
|
# A directory holding only hidden entries holds no versions, so it must be
|
||||||
|
# treated as empty: otherwise, with nullglob unset, `find` is handed the
|
||||||
|
# literal `*` pattern and errors out (#3727).
|
||||||
|
mkdir -p "$(nvm_version_dir new)"
|
||||||
|
touch "$(nvm_version_dir new)/.hidden"
|
||||||
|
|
||||||
|
try_err nvm ls
|
||||||
|
[ -z "${CAPTURED_STDERR-}" ] || die "nvm ls should not write to stderr: ${CAPTURED_STDERR-}"
|
||||||
|
|
||||||
|
# Hidden entries must not hide installed versions.
|
||||||
|
make_fake_node v0.0.1
|
||||||
|
|
||||||
|
try_err nvm ls
|
||||||
|
[ -z "${CAPTURED_STDERR-}" ] || die "nvm ls should not write to stderr: ${CAPTURED_STDERR-}"
|
||||||
|
|
||||||
|
try nvm_ls
|
||||||
|
case "${CAPTURED_STDOUT-}" in
|
||||||
|
*v0.0.1*) ;;
|
||||||
|
*) die "expected v0.0.1 in >${CAPTURED_STDOUT-}<" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
cleanup
|
||||||
Reference in new issue
Block a user