Skip to content

Commit

Permalink
[Robustness] use command dirname
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 11, 2023
1 parent ec9a755 commit ccbe837
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions nvm-exec
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

SOURCE=${BASH_SOURCE[0]}
if [ -L "${SOURCE}" ]; then
command cd "$(dirname "${SOURCE}")" || exit 127
command cd "$(command dirname "${SOURCE}")" || exit 127
SOURCE="$(readlink "${SOURCE}")"
fi
DIR="$(command cd "$(dirname "${SOURCE}")" && pwd)"
DIR="$(command cd "$(command dirname "${SOURCE}")" && pwd)"

unset NVM_CD_FLAGS

Expand Down
12 changes: 6 additions & 6 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ if [ -z "${NVM_DIR-}" ]; then
NVM_SCRIPT_SOURCE="${BASH_SOURCE[0]}"
fi
# shellcheck disable=SC2086
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" >/dev/null && \pwd)"
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(command dirname "${NVM_SCRIPT_SOURCE:-$0}")" >/dev/null && \pwd)"
export NVM_DIR
else
# https://unix.stackexchange.com/a/198289
Expand Down Expand Up @@ -431,11 +431,11 @@ nvm_tree_contains_path() {
local previous_pathdir
previous_pathdir="${node_path}"
local pathdir
pathdir=$(dirname "${previous_pathdir}")
pathdir=$(command dirname "${previous_pathdir}")
while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&
[ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
previous_pathdir="${pathdir}"
pathdir=$(dirname "${previous_pathdir}")
pathdir=$(command dirname "${previous_pathdir}")
done
[ "${pathdir}" = "${tree}" ]
}
Expand Down Expand Up @@ -2152,7 +2152,7 @@ nvm_install_binary() {
nvm_echo "Downloading and installing ${NODE_OR_IOJS-} ${VERSION}..."
TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" binary "${TYPE-}" "${VERSION}" | command tail -1)"
if [ -f "${TARBALL}" ]; then
TMPDIR="$(dirname "${TARBALL}")/files"
TMPDIR="$(command dirname "${TARBALL}")/files"
fi

if nvm_install_binary_extract "${NVM_OS}" "${PREFIXED_VERSION}" "${VERSION}" "${TARBALL}" "${TMPDIR}"; then
Expand Down Expand Up @@ -2519,7 +2519,7 @@ nvm_install_source() {

TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \
[ -f "${TARBALL}" ] && \
TMPDIR="$(dirname "${TARBALL}")/files" && \
TMPDIR="$(command dirname "${TARBALL}")/files" && \
if ! (
# shellcheck disable=SC2086
command mkdir -p "${TMPDIR}" && \
Expand Down Expand Up @@ -3874,7 +3874,7 @@ nvm() {
local NVM_EXEC
NVM_EXEC="${NVM_DIR}/nvm-exec"
if [ ! -f "${NVM_EXEC}" ]; then
NVM_EXEC="$(dirname "${BASH_SOURCE[0]-}")/nvm-exec"
NVM_EXEC="$(command dirname "${BASH_SOURCE[0]-}")/nvm-exec"
fi
NODE_VERSION="${VERSION}" "${NVM_EXEC}" "$@"
;;
Expand Down

0 comments on commit ccbe837

Please sign in to comment.