Skip to content
Myr

[Fix] `nvm install`: do not remove the caller's `TMPDIR` after a failed download

Before adoption: this commit came in with the history the project adopted, so no landing records it.

`nvm_install_binary` and `nvm_install_source` declared `local TMPDIR` without initializing it, and remove it with `rm -rf` on failure. dash's `local` keeps the caller's value, as does bash's when `TMPDIR` is passed as a prefix assignment (`TMPDIR=… nvm install`), so a failed download removed the caller's temp directory; on macOS, `tar` instead blocked reading the archive from the terminal.

authored by Jordan Harband · committed by Jordan Harband · parent a8bb497 · Browse files · 2 files+38 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+38 added−0 removed

  • tests:+30 added−0 removed
  • other:+8 added−0 removed

2 files+38 added−0 removed

added:test/fast/Unit tests/nvm_install_binary and nvm_install_source do not remove an inherited TMPDIR+30 added
1#!/bin/sh23WORK="${PWD}/nvm-inherited-tmpdir-work.$$"45cleanup() {6 command rm -rf "${WORK}"7 unset -f cleanup die nvm_download_artifact8}9die () { echo "$@" ; cleanup ; exit 1; }1011: nvm.sh12\. ../../../nvm.sh1314nvm_download_artifact() { return 1; }1516make_canary() {17 command rm -rf "${WORK}/tmp"18 command mkdir -p "${WORK}/tmp"19 echo canary > "${WORK}/tmp/canary"20}2122make_canary23TMPDIR="${WORK}/tmp" nvm_install_binary node std 8.0.0 0 < /dev/null > /dev/null 2>&124[ -f "${WORK}/tmp/canary" ] || die 'nvm_install_binary removed the TMPDIR it inherited after a failed download'2526make_canary27TMPDIR="${WORK}/tmp" nvm_install_source node std 8.0.0 < /dev/null > /dev/null 2>&128[ -f "${WORK}/tmp/canary" ] || die 'nvm_install_source removed the TMPDIR it inherited after a failed download'2930cleanup
modified:nvm.sh+8 added
2773 unmodified lines
2774 if [ -z "${NVM_OS}" ]; then2775 return 22776 fi27772778 # dash's `local` keeps the caller's value, and TMPDIR is usually set: it is2779 # later removed with `rm -rf`, so it must not start as the system temp dir2780 local TARBALL2781 TARBALL=''2782 local TMPDIR2783 TMPDIR=''27842785 local PROGRESS_BAR2786 local NODE_OR_IOJS2787 if [ "${FLAVOR}" = 'node' ]; then
391 unmodified lines
3179 MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}"3180 fi3181 fi31823183 # see nvm_install_binary: these must not inherit TMPDIR, which is removed on failure3184 local TARBALL3185 TARBALL=''3186 local TMPDIR3187 TMPDIR=''3188 local VERSION_PATH3189 VERSION_PATH=''31903191 if [ "${NVM_NO_PROGRESS-}" = "1" ]; then3192 # --silent, --show-error, use short option as @samrocketman mentions the compatibility issue.3193 PROGRESS_BAR="-sS"
2231 unmodified lines