Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

Fix checksum check condition to not try url if already found in config files#4707

Merged
eregon merged 4 commits intorvm:masterfrom
eregon:fix-checksum
Jun 19, 2019
Merged

Fix checksum check condition to not try url if already found in config files#4707
eregon merged 4 commits intorvm:masterfrom
eregon:fix-checksum

Conversation

@eregon
Copy link
Contributor

@eregon eregon commented May 30, 2019

Fix condition to only try curl if no checksum is found

Only try to get the checksum from the network after checking the config files (avoiding extra curl queries if not needed).

This notably fixes the checksum check for TruffleRuby.

cc @pkuczynski @mpapis

__rvm_checksum_none || return 0
done

# Only try to get the checksum from the network after checking the config files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we keep the previous version but do:

[[ -z "${_checksum_md5:-}" && $_name == http* ]] ||		
        _checksum_md5="$(__rvm_curl -s -L $_name.md5)"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@eregon
Copy link
Contributor Author

eregon commented Jun 6, 2019

@pkuczynski Could you take a second look at this fix?


[[ -n "${_checksum_sha512:-}" && $_name == http* ]] ||
_checksum_sha512="$(__rvm_curl -s -L $_name.sha512)"
__rvm_checksum_none || return 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@eregon eregon Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@eregon eregon Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to the equivalent __rvm_checksum_any && return 0.

@pkuczynski
Copy link
Member

Looks better now I think. @mpapis whats your view on this?

eregon added 4 commits June 19, 2019 11:32
* 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.
@eregon
Copy link
Contributor Author

eregon commented Jun 19, 2019

Here is a build which ended up downloading truffleruby twice because of this bug:
https://travis-ci.org/ruby/mspec/jobs/538473966#L476

@eregon
Copy link
Contributor Author

eregon commented Jun 19, 2019

I'll merge this, it fixes an important bug and allows checksum verification to work again.

@pkuczynski
Copy link
Member

Sorry for not being able to look at this earlier...

@pkuczynski pkuczynski added this to the rvm-1.29.9 milestone Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants