Fix checksum check condition to not try url if already found in config files#4707
Fix checksum check condition to not try url if already found in config files#4707eregon merged 4 commits intorvm:masterfrom
Conversation
| __rvm_checksum_none || return 0 | ||
| done | ||
|
|
||
| # Only try to get the checksum from the network after checking the config files |
There was a problem hiding this comment.
Why don't we keep the previous version but do:
[[ -z "${_checksum_md5:-}" && $_name == http* ]] ||
_checksum_md5="$(__rvm_curl -s -L $_name.md5)"
There was a problem hiding this comment.
I think that's incorrect too, it would run curl if $_name does not start with http, even if the checksum is already set. My first commit e370ad6 I think does the minimal fix.
But it seems highly desirable to avoid curl calls entirely if there are already entries in the config files. Since the code iterates over multiple _name, we need to split the loop, so e.g. config files for the second _name (e.g., truffleruby-19.0.0-linux-amd64.tar.gz) are checked before a URL for the first _name (e.g., a URL). I think this approach somewhat concurs with @mpapis's comment: #4650 (comment), i.e., avoiding needless curl calls.
I also find a pair of if a lot more readable and easier to reason about than multiple &&/|| with side effects.
|
@pkuczynski Could you take a second look at this fix? |
scripts/functions/checksum
Outdated
|
|
||
| [[ -n "${_checksum_sha512:-}" && $_name == http* ]] || | ||
| _checksum_sha512="$(__rvm_curl -s -L $_name.sha512)" | ||
| __rvm_checksum_none || return 0 |
There was a problem hiding this comment.
this will never get to checking URL's if there was no checksum locally, __rvm_checksum_none has to be moved to the end of the function, outside of loops
There was a problem hiding this comment.
Bash conditions are hard to read.
__rvm_checksum_none()
{
[[ -z "${_checksum_md5:-}" && -z "${_checksum_sha512:-}" ]]
}So that returns "true" if both are unset, i.e, it returns "false" if any is set and therefore || return 0 returns if any is set.
This is also done at the function entry BTW, and already before in the loop.
So that seems incorrect in the case we get one of the checksum, but not the other, right?
I think we should return only if both are set then, i.e., replace that with __rvm_checksum_all && return 0. I'll do that.
There was a problem hiding this comment.
@mpapis Should this function return 0 or 1 if we found only one of the checksums?
__rvm_checksum_validate_file seems happy if only one is set.
So __rvm_checksum_any && return 0 would be right (and the original __rvm_checksum_none || return 0 too) but __rvm_checksum_any && return 0 is probably easier to read?
There was a problem hiding this comment.
I changed to the equivalent __rvm_checksum_any && return 0.
|
Looks better now I think. @mpapis whats your view on this? |
* This would cause checksums to fail even if they exist in the config files, as long as the given URL does not exist. * This bug was introduced by rvm#4650
* It's equivalent to `__rvm_checksum_none || return 0` but is easier to read as there is no negation.
|
Here is a build which ended up downloading truffleruby twice because of this bug: |
|
I'll merge this, it fixes an important bug and allows checksum verification to work again. |
|
Sorry for not being able to look at this earlier... |
Fix condition to only try
curlif no checksum is foundOnly try to get the checksum from the network after checking the config files (avoiding extra
curlqueries if not needed).This notably fixes the checksum check for TruffleRuby.
cc @pkuczynski @mpapis