From 4b1100e515d7fa1a949b232672e4ca30937bc0ea Mon Sep 17 00:00:00 2001 From: DeeDeeG Date: Wed, 29 Jan 2020 16:20:15 -0500 Subject: [PATCH] [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. --- nvm.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index 32aacff..c40c607 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3687,10 +3687,32 @@ EOF } nvm_supports_xz() { - if [ -z "${1-}" ] || ! command which xz >/dev/null 2>&1; then + if [ -z "${1-}" ]; then return 1 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 if nvm_is_merged_node_version "${1}"; then return 0 @@ -3706,8 +3728,6 @@ nvm_supports_xz() { return 0 fi - local NVM_OS - NVM_OS="$(nvm_get_os)" case "${NVM_OS}" in darwin) # darwin only has xz for io.js v2.3.2 and later