[New] `nvm_supports_xz`: Add Mac/FreeBSD xz platform support checks

macOS only supports extracting xz tarballs with `tar` in 10.9 and up.

GNU tar needs an `xz` executable on the `PATH` to extract xz tarballs.

(These are the most common variants of tar, so until further testing
is done, conservatively assume all variants of tar (other than the one
shipped with macOS) need an xz executable on the PATH in order to
decompress xz tarballs.)

Fixes #2155.
DeeDeeG 2020-01-29 16:20:15 -05:00 committed by Jordan Harband
parent f6d11bae41
commit 4b1100e515
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
1 changed files with 23 additions and 3 deletions

26
nvm.sh
View File

@ -3687,10 +3687,32 @@ EOF
} }
nvm_supports_xz() { nvm_supports_xz() {
if [ -z "${1-}" ] || ! command which xz >/dev/null 2>&1; then if [ -z "${1-}" ]; then
return 1 return 1
fi fi
local NVM_OS
NVM_OS="$(nvm_get_os)"
if [ "_${NVM_OS}" = '_darwin' ]; then
local MACOS_VERSION
MACOS_VERSION="$(sw_vers -productVersion)"
if nvm_version_greater "10.9.0" "${MACOS_VERSION}"; then
# macOS 10.8 and earlier doesn't support extracting xz-compressed tarballs with tar
return 1
fi
elif [ "_${NVM_OS}" = '_freebsd' ]; then
if ! [ -e '/usr/lib/liblzma.so' ]; then
# FreeBSD without /usr/lib/liblzma.so doesn't support extracting xz-compressed tarballs with tar
return 1
fi
else
if ! command which xz >/dev/null 2>&1; then
# Most OSes without xz on the PATH don't support extracting xz-compressed tarballs with tar
# (Should correctly handle Linux, SmartOS, maybe more)
return 1
fi
fi
# all node versions v4.0.0 and later have xz # all node versions v4.0.0 and later have xz
if nvm_is_merged_node_version "${1}"; then if nvm_is_merged_node_version "${1}"; then
return 0 return 0
@ -3706,8 +3728,6 @@ nvm_supports_xz() {
return 0 return 0
fi fi
local NVM_OS
NVM_OS="$(nvm_get_os)"
case "${NVM_OS}" in case "${NVM_OS}" in
darwin) darwin)
# darwin only has xz for io.js v2.3.2 and later # darwin only has xz for io.js v2.3.2 and later