From 814319d7c087319ce1c01378053cb3fbfd768fdf Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Tue, 26 Aug 2014 23:52:53 -0500 Subject: [PATCH 1/3] Make shasum the lowest priority checksum command. This fixes false "Checksums do not match" errors on systems where shasum is a symlink to sha256sum or otherwise. --- nvm.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index 500e472..71cbd9b 100644 --- a/nvm.sh +++ b/nvm.sh @@ -278,12 +278,12 @@ nvm_ls_remote() { } nvm_checksum() { - if nvm_has "shasum"; then - checksum=$(shasum $1 | \awk '{print $1}') + if nvm_has "sha1sum"; then + checksum=$(sha1sum $1 | \awk '{print $1}') elif nvm_has "sha1"; then checksum=$(sha1 -q $1) else - checksum=$(sha1sum $1 | \awk '{print $1}') + checksum=$(shasum $1 | \awk '{print $1}') fi if [ "$checksum" = "$2" ]; then From 429656bc4149b8d682cbc3a0f5dce21c419db74f Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sat, 30 Aug 2014 21:54:46 -0500 Subject: [PATCH 2/3] Add unit tests for nvm_checksum. --- test/fast/Unit tests/nvm_checksum | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 test/fast/Unit tests/nvm_checksum diff --git a/test/fast/Unit tests/nvm_checksum b/test/fast/Unit tests/nvm_checksum new file mode 100755 index 0000000..408659b --- /dev/null +++ b/test/fast/Unit tests/nvm_checksum @@ -0,0 +1,18 @@ +#!/bin/sh + +cleanup () { + rm tmp/emptyfile tmp/testfile + rmdir tmp +} +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +mkdir -p tmp +touch tmp/emptyfile +echo -n "test" > tmp/testfile + +nvm_checksum tmp/emptyfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" || die "nvm_checksum on an empty file did not match the SHA1 digest of the empty string" +nvm_checksum tmp/testfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" && die "nvm_checksum allowed a bad checksum" + +cleanup From e8056ac460e2fdaf7cb97174f37c1d86b2d2f9f9 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Sat, 30 Aug 2014 21:57:17 -0500 Subject: [PATCH 3/3] Run cleanup on die in nvm_checksum unit test. --- test/fast/Unit tests/nvm_checksum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fast/Unit tests/nvm_checksum b/test/fast/Unit tests/nvm_checksum index 408659b..73cf1f1 100755 --- a/test/fast/Unit tests/nvm_checksum +++ b/test/fast/Unit tests/nvm_checksum @@ -4,7 +4,7 @@ cleanup () { rm tmp/emptyfile tmp/testfile rmdir tmp } -die () { echo $@ ; exit 1; } +die () { echo $@ ; cleanup; exit 1; } . ../../../nvm.sh