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

update GitHub tarball sha256 hashes #18073

Merged
merged 2 commits into from Sep 14, 2017
Merged

update GitHub tarball sha256 hashes #18073

merged 2 commits into from Sep 14, 2017

Conversation

peff
Copy link
Contributor

@peff peff commented Sep 14, 2017

GitHub recently applied an old Git bugfix to their servers (git/git@22f0dcd), which caused the byte representation of some tarballs to change.

I computed the mapping of old to new tarballs by building two versions of git, with and without that commit, and then computing the archive hash for each case. I used this script (note the "git.with" and "git.without" builds were in my $PATH):

#!/usr/bin/perl

sub hash {
  my ($git, $repo, $version) = @_;
  my $prefix = $version;
  $prefix =~ s/^v//;
  $prefix = "$repo-$prefix/";
  my $cmd = "$git -C tmp.git archive --format=tar.gz" .
            " --prefix=" . quotemeta($prefix) .
            " " . quotemeta($version) .
            " | sha256sum";
  my $hash = `$cmd`;
  chomp $hash;
  $hash =~ s/\s*-$//;
  return $hash;
}

while (<>) {
  if (m{https://github.com/(.*?)/(.*?)/archive/(.*?).tar.gz}) {
        system(qw(rm -rf tmp.git));
        system(qw(git clone --bare), "https://github.com/$1/$2.git", "tmp.git");
        $? and next; # skip clone failures

        my $old = hash("git.without", $2, $3);
        my $new = hash("git.with", $2, $3);
        if ($old ne $new) {
          print "$old $new $1/$2\n";
          print STDERR "$1/$2\n  $old\n  $new\n";
        }
  }
}

That script generated 94 entries. With that output saved to the file "map", I was then able to adjust the hashes in place:

#!/bin/sh

git ls-files Formula | xargs perl -i -pe '
  BEGIN {
	  open(my $fh, "<map");
	  while (<$fh>) {
		  my ($from, $to, $repo) = split;
		  $map{$from} = $to;
	  }
  }

  s{sha256 "(.*?)"}
  {
	  my $hash = $1;
	  if (exists $map{$hash}) {
		  print STDERR "replacing $hash with $map{$hash}\n";
		  $hash = $map{$hash};
	  }
	  qq(sha256 "$hash")
  }e;
'

and commit the result. Note that there aren't 94 updates in this commit, because the previous commits had already picked up most of these changes.

/cc @ilovezfs #18044

@ilovezfs
Copy link
Contributor

Thanks @peff! 🙇‍♂️

Do you mind splitting this into one commit per formula?

@peff
Copy link
Contributor Author

peff commented Sep 14, 2017

@ilovezfs Done.

@ilovezfs
Copy link
Contributor

@peff thanks. It looks like the osquery commit took teleport along for the ride :)

@ilovezfs
Copy link
Contributor

May need to rebase your local repo since teleport was fixed already in 447ae95.

These are due to non-byte-stable updates to GitHub's
generated archives.
These are due to non-byte-stable updates to GitHub's
generated archives.
@peff
Copy link
Contributor Author

peff commented Sep 14, 2017

Whoops, apparently I'm incompetent at using Git. Should be fixed now.

@ilovezfs
Copy link
Contributor

Whoops, apparently I'm incompetent at using Git

Hehe. You made me think of https://xkcd.com/1597/

@ilovezfs ilovezfs merged commit d295b1c into Homebrew:master Sep 14, 2017
@ilovezfs
Copy link
Contributor

Thanks for the great scripts and your first contribution to Homebrew, @peff!

@peff
Copy link
Contributor Author

peff commented Sep 14, 2017

@ilovezfs Let me know if you'd like me to run the same scripts on another set of formulas. I wrote them in such a way that anybody could run and reproduce, but obviously they run a lot faster from inside GitHub's datacenter.

@peff peff deleted the tarball-hash-update branch September 14, 2017 13:40
@ilovezfs
Copy link
Contributor

@peff
Copy link
Contributor Author

peff commented Sep 26, 2017

@ilovezfs Sorry, for some reason I totally missed your response earlier.

I just ran it over those other repositories. homebrew-science has only the rstudio case covered by https://github.com/Homebrew/homebrew-science/pull/6315. homebrew-php has one case, for which I've opened https://github.com/Homebrew/homebrew-php/pull/4484. And there were none in homebrew-apache.

@Homebrew Homebrew locked and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants