mirror of
				https://github.com/nvm-sh/nvm.git
				synced 2025-10-31 10:15:53 +08:00 
			
		
		
		
	Merge pull request #512 from kevinwang/shasum-lowest-priority
Make shasum the lowest priority checksum command.
This commit is contained in:
		
							
								
								
									
										6
									
								
								nvm.sh
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								nvm.sh
									
									
									
									
									
								
							| @@ -284,12 +284,12 @@ nvm_ls_remote() { | |||||||
| } | } | ||||||
|  |  | ||||||
| nvm_checksum() { | nvm_checksum() { | ||||||
|   if nvm_has "shasum"; then |   if nvm_has "sha1sum"; then | ||||||
|     checksum=$(shasum $1 | \awk '{print $1}') |     checksum=$(sha1sum $1 | \awk '{print $1}') | ||||||
|   elif nvm_has "sha1"; then |   elif nvm_has "sha1"; then | ||||||
|     checksum=$(sha1 -q $1) |     checksum=$(sha1 -q $1) | ||||||
|   else |   else | ||||||
|     checksum=$(sha1sum $1 | \awk '{print $1}') |     checksum=$(shasum $1 | \awk '{print $1}') | ||||||
|   fi |   fi | ||||||
|  |  | ||||||
|   if [ "$checksum" = "$2" ]; then |   if [ "$checksum" = "$2" ]; then | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								test/fast/Unit tests/nvm_checksum
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										18
									
								
								test/fast/Unit tests/nvm_checksum
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | #!/bin/sh | ||||||
|  |  | ||||||
|  | cleanup () { | ||||||
|  |   rm tmp/emptyfile tmp/testfile | ||||||
|  |   rmdir tmp | ||||||
|  | } | ||||||
|  | die () { echo $@ ; cleanup; 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 | ||||||
		Reference in New Issue
	
	Block a user