Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for OpenBSD's native tar #1972

Open
wants to merge 9 commits into
base: master
from
72 nvm.sh
@@ -1582,6 +1582,7 @@ nvm_get_os() {
Darwin\ *) NVM_OS=darwin ;;
SunOS\ *) NVM_OS=sunos ;;
FreeBSD\ *) NVM_OS=freebsd ;;
OpenBSD\ *) NVM_OS=openbsd ;;
AIX\ *) NVM_OS=aix ;;
esac
nvm_echo "${NVM_OS-}"
@@ -1907,6 +1908,58 @@ nvm_download_artifact() {
nvm_echo "${TARBALL}"
}

# args: tarball path, NVM_OS var
nvm_extract_tar_artifact() {
local tar_compression_flag
local TARBALL
local TAR_COMMAND_SUFFIX
local TMPDIR
local NVM_OS
local tar

TARBALL="${1}"
NVM_OS="${2}"

tar='tar'
if [ "${NVM_OS}" = 'aix' ]; then
tar='gtar'
fi

tar_compression_flag='z'

if nvm_supports_xz "${VERSION}" && [ "_$NVM_OS" != "_openbsd" ]; then

This comment has been minimized.

Copy link
@ljharb

ljharb Dec 31, 2018

Collaborator

Is there any way to determine -J support that doesn't involve checking the OS? (ie, feature test instead of user agent sniff)

This comment has been minimized.

Copy link
@aramisf

aramisf Jan 2, 2019

Author

We could run tar -J and check if the stderr's first line matches:

tar: unknown option -- J

But I have mixed feelings about this, haha. What do you think?

This comment has been minimized.

Copy link
@ljharb

ljharb Jan 2, 2019

Collaborator

lol, i mean, if every single possible version of tar will either error with the same error message, or support -J, then that's pretty robust

This comment has been minimized.

Copy link
@aramisf

aramisf Jan 4, 2019

Author

I couldn't test all possible versions, but GNU tar 1.28 on Linux and bsdtar 2.8.3 on macosx all provide sufficiently clear error messages to understand whether the support for J option exists.

I'm adding a test to the specific error string given by tar on OpenBSD, that should solve the issue for OpenBSD. Since I didn't test on other operating systems (other than the ones mentioned above), I'm not sure it is enough to go through it without checking the OS. On the other hand this situation only happens on OpenBSD.

I'm uploading a new version.

tar_compression_flag='J'
This conversation was marked as resolved by ljharb

This comment has been minimized.

Copy link
@ljharb

ljharb Jan 4, 2019

Collaborator

let's move this if block into the else below, since that's the only path it matters.

This comment has been minimized.

Copy link
@aramisf

aramisf Jan 5, 2019

Author

Ok, I'll try to upload it today.

This comment has been minimized.

Copy link
@aramisf
fi

if [ "_$NVM_OS" = "_openbsd" ] && nvm_has xz; then
This conversation was marked as resolved by aramisf

This comment has been minimized.

Copy link
@ljharb

ljharb Jan 2, 2019

Collaborator

if the version doesn't support xz, then it shouldn't try to use xz on it.

Suggested change
if [ "_$NVM_OS" = "_openbsd" ] && nvm_has xz; then
if [ "_$NVM_OS" = "_openbsd" ] && nvm_has xz && nvm_supports_xz "${VERSION}"; then
if [ -f "${TARBALL}" ]; then
command xz -dk "${TARBALL}"
fi

TARBALL=${TARBALL%.xz}
tar_compression_flag=
TAR_COMMAND_SUFFIX=
TMPDIR="$(dirname "${TARBALL}")"

else
TAR_COMMAND_SUFFIX="--strip-components 1"
TMPDIR="$(dirname "${TARBALL}")/files"
fi

if [ -f "${TARBALL}" ] && [ -d "${TMPDIR}" ]; then
# shellcheck disable=SC2086
command ${tar} -x${tar_compression_flag}f ${TARBALL} -C ${TMPDIR} ${TAR_COMMAND_SUFFIX}
This conversation was marked as resolved by aramisf

This comment has been minimized.

Copy link
@ljharb

ljharb Jan 4, 2019

Collaborator
Suggested change
command ${tar} -x${tar_compression_flag}f ${TARBALL} -C ${TMPDIR} ${TAR_COMMAND_SUFFIX}
command ${tar} "-x${tar_compression_flag}f" "${TARBALL}" -C "${TMPDIR}" ${TAR_COMMAND_SUFFIX}

?

This comment has been minimized.

Copy link
@aramisf
fi


if [ "_$NVM_OS" = "_openbsd" ]; then
BASE=$(basename "${TMPDIR}")
TMPDIR="${TMPDIR}/${BASE}"
fi

nvm_echo "$TMPDIR"
}

nvm_get_make_jobs() {
if nvm_is_natural_num "${1-}"; then
NVM_MAKE_JOBS="$1"
@@ -2004,7 +2057,7 @@ nvm_install_source() {
make='gmake'
MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}"
;;
'darwin')
'openbsd' | 'darwin')
MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}"
;;
'aix')
@@ -2018,18 +2071,6 @@ nvm_install_source() {
fi
fi

local tar_compression_flag
tar_compression_flag='z'
if nvm_supports_xz "${VERSION}"; then
tar_compression_flag='J'
fi

local tar
tar='tar'
if [ "${NVM_OS}" = 'aix' ]; then
tar='gtar'
fi

local TARBALL
local TMPDIR
local VERSION_PATH
@@ -2045,11 +2086,8 @@ 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="$(nvm_extract_tar_artifact "${TARBALL}" "${NVM_OS}" | command tail -1)" && \
if ! (
# shellcheck disable=SC2086
command mkdir -p "${TMPDIR}" && \
command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 && \
VERSION_PATH="$(nvm_version_path "${PREFIXED_VERSION}")" && \
nvm_cd "${TMPDIR}" && \
nvm_echo '$>'./configure --prefix="${VERSION_PATH}" $ADDITIONAL_PARAMETERS'<' && \
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.