[Fix] ls: list versions whose directory is a symlink
nvm_ls collects installed versions with `find <dirs>/* -name . -o -type d -prune -o -path ...`, and `-type d` is false for a symlink, so a version dir that links to another volume was skipped from the listing entirely - while `nvm version`, `nvm which` and `nvm use` all kept working on it. Have that find follow symlinks, which makes linked-in versions visible and still ignores a broken link. Fixes #617.
This commit is contained in:
1 parent
970ed9ea18
commit
c6bf252f7d
3 files changed
+29
-1
No files matched your search
@@ -2516,7 +2516,7 @@ nvm_ls() {
|
||||
NVM_DIR_SED="$(nvm_echo "${NVM_DIR}" | command sed 's/[][\.*^$#]/\\&/g')"
|
||||
local NVM_VERSION_DIR_IOJS_SED
|
||||
NVM_VERSION_DIR_IOJS_SED="$(nvm_echo "${NVM_VERSION_DIR_IOJS}" | command sed 's/[][\.*^$#]/\\&/g')"
|
||||
VERSIONS="$(command find "${NVM_DIRS_TO_SEARCH1}"/* "${NVM_DIRS_TO_SEARCH2}"/* "${NVM_DIRS_TO_SEARCH3}"/* -name . -o -type d -prune -o -path "${PATTERN}*" \
|
||||
VERSIONS="$(command find -L "${NVM_DIRS_TO_SEARCH1}"/* "${NVM_DIRS_TO_SEARCH2}"/* "${NVM_DIRS_TO_SEARCH3}"/* -name . -o -type d -prune -o -path "${PATTERN}*" \
|
||||
| command sed -e "
|
||||
s#${NVM_VERSION_DIR_IOJS_SED}/#versions/${NVM_IOJS_PREFIX}/#;
|
||||
s#^${NVM_DIR_SED}/##;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
make_fake_node v0.0.1 || die 'unable to make a fake node'
|
||||
|
||||
# a version that lives outside of NVM_DIR and is linked in, which is how some
|
||||
# users keep their versions on a separate volume
|
||||
REAL_DIR="$(cd ../../.. && pwd)/symlink-target"
|
||||
rm -rf "${REAL_DIR}"
|
||||
mkdir -p "${REAL_DIR}/v0.0.2/bin" || die 'unable to make the link target dir'
|
||||
make_echo "${REAL_DIR}/v0.0.2/bin/node" v0.0.2 || die 'unable to make fake node bin'
|
||||
rm -f "$(nvm_version_path v0.0.2)"
|
||||
ln -s "${REAL_DIR}/v0.0.2" "$(nvm_version_path v0.0.2)" || die 'unable to symlink the version dir'
|
||||
|
||||
nvm ls | grep v0.0.1 >/dev/null || die "v0.0.1 not found in: $(nvm ls)"
|
||||
nvm ls | grep v0.0.2 >/dev/null || die "the symlinked v0.0.2 not found in: $(nvm ls)"
|
||||
nvm ls 0.0 | grep v0.0.2 >/dev/null || die "the symlinked v0.0.2 not found with a pattern in: $(nvm ls 0.0)"
|
||||
nvm ls 0.0.2 | grep v0.0.2 >/dev/null || die "the symlinked v0.0.2 not found with an exact version in: $(nvm ls 0.0.2)"
|
||||
|
||||
# leave no trace, so the tests that compare `nvm ls` output verbatim are unaffected
|
||||
rm -f "$(nvm_version_path v0.0.2)"
|
||||
rm -rf "${REAL_DIR}"
|
||||
@@ -14,3 +14,4 @@ rm -rf ../../../v0.20.3
|
||||
rm -rf ../../../versions
|
||||
rm -f ../../../alias/stable
|
||||
rm -f ../../../alias/unstable
|
||||
rm -rf ../../../symlink-target
|
||||
Reference in new issue
Block a user