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

Support xz tarballs if available #823

Merged
merged 1 commit into from
Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -999,16 +999,24 @@ nvm_install_merged_node_binary() {
local url
local sum
local NODE_PREFIX
local compression
compression="gz"
local tar_compression_flag
tar_compression_flag="x"
if nvm_supports_xz "$VERSION"; then
compression="xz"
tar_compression_flag="J"
fi
NODE_PREFIX="$(nvm_node_prefix)"

if [ -n "$NVM_OS" ]; then
t="$VERSION-$NVM_OS-$(nvm_get_arch)"
url="$MIRROR/$VERSION/$NODE_PREFIX-${t}.tar.gz"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $NODE_PREFIX-${t}.tar.gz | command awk '{print $1}')"
url="$MIRROR/$VERSION/$NODE_PREFIX-${t}.tar.${compression}"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $NODE_PREFIX-${t}.tar.${compression} | command awk '{print $1}')"
local tmpdir
tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball
tmptarball="$tmpdir/node-${t}.tar.gz"
tmptarball="$tmpdir/node-${t}.tar.${compression}"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
echo "Downloading $url..." && \
Expand All @@ -1022,7 +1030,7 @@ nvm_install_merged_node_binary() {
[ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for node.js v4.0 and later" >&2 && \
# nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \
command mkdir -p "$VERSION_PATH" && \
command mv "$tmpdir"/* "$VERSION_PATH"
Expand Down Expand Up @@ -1066,16 +1074,24 @@ nvm_install_iojs_binary() {
local t
local url
local sum
local compression
compression="gz"
local tar_compression_flag
tar_compression_flag="x"
if nvm_supports_xz "$VERSION"; then
compression="xz"
tar_compression_flag="J"
fi

if [ -n "$NVM_OS" ]; then
if nvm_binary_available "$VERSION"; then
t="$VERSION-$NVM_OS-$(nvm_get_arch)"
url="$MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.gz"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.gz | command awk '{print $1}')"
url="$MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.${compression}"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.${compression} | command awk '{print $1}')"
local tmpdir
tmpdir="$NVM_DIR/bin/iojs-${t}"
local tmptarball
tmptarball="$tmpdir/iojs-${t}.tar.gz"
tmptarball="$tmpdir/iojs-${t}.tar.${compression}"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
echo "Downloading $url..." && \
Expand All @@ -1089,7 +1105,7 @@ nvm_install_iojs_binary() {
[ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \
# nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \
command mkdir -p "$VERSION_PATH" && \
command mv "$tmpdir"/* "$VERSION_PATH"
Expand Down Expand Up @@ -1662,9 +1678,9 @@ nvm() {
fi
# Delete all files related to target version.
command rm -rf "$NVM_DIR/src/$NVM_PREFIX-$VERSION" \
"$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.gz" \
"$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.*" \
"$NVM_DIR/bin/$NVM_PREFIX-${t}" \
"$NVM_DIR/bin/$NVM_PREFIX-${t}.tar.gz" \
"$NVM_DIR/bin/$NVM_PREFIX-${t}.tar.*" \
"$VERSION_PATH" 2>/dev/null
echo "$NVM_SUCCESS_MSG"

Expand Down Expand Up @@ -2200,7 +2216,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
nvm_print_npm_version nvm_npm_global_modules \
nvm_has_system_node nvm_has_system_iojs \
nvm_download nvm_get_latest nvm_has nvm_get_latest \
nvm_supports_source_options > /dev/null 2>&1
nvm_supports_source_options nvm_supports_xz > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )
Expand All @@ -2214,6 +2230,11 @@ nvm_supports_source_options() {
[ "_$(echo 'echo $1' | . /dev/stdin yes 2> /dev/null)" = "_yes" ]
}

nvm_supports_xz() {
command which xz 2>&1 >/dev/null && \
nvm_version_greater_than_or_equal_to "$1" "2.3.2"
}

NVM_VERSION="$(nvm_alias default 2>/dev/null || echo)"
if nvm_supports_source_options && [ "_$1" = "_--install" ]; then
if [ -n "$NVM_VERSION" ]; then
Expand Down
36 changes: 36 additions & 0 deletions test/fast/Unit tests/nvm_supports_xz
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

die () { echo $@ ; exit 1; }

. ../../../nvm.sh

OLDPATH=$PATH
TEST_PATH=../../xz-test

mkdir $TEST_PATH
touch ../../xz-test/xz
chmod +x ../../xz-test/xz

export PATH=$TEST_PATH:$PATH

$(nvm_supports_xz "v2.3.2") || \
die "expected 'nvm_supports_xz v2.3.2' to exit with 0"

$(nvm_supports_xz "v0.12.7") && \
die "expected 'nvm_supports_xz v0.12.7' to exit with 1"


# set up for a failure by having a minimal toolset available
# but remove xz
ln -s /usr/bin/which $TEST_PATH/which
ln -s /usr/bin/command $TEST_PATH/command
ln -s /usr/bin/awk $TEST_PATH/awk
ln -s $(which rm) $TEST_PATH/rm

export PATH=$TEST_PATH
rm $TEST_PATH/xz

$(nvm_supports_xz "v2.3.2") && \
die "expected 'nvm_supports_xz v2.3.2' with a missing xz binary to exit with 1"

export PATH=$OLDPATH
2 changes: 1 addition & 1 deletion test/fast/teardown
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

type setopt >/dev/null 2>&1 && setopt NULL_GLOB
type shopt >/dev/null 2>&1 && shopt -s nullglob
rm -fR v* src alias
rm -fR v* src alias test/test-xz
)