From 336e34ce80bc54c9f9c6701d6c652fbdfa07b700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20Soul=C3=A9?= Date: Wed, 9 Mar 2022 22:32:58 +0100 Subject: [PATCH] fix: in some cases, requiring a specific version could fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime Soulé --- install-go.pl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/install-go.pl b/install-go.pl index 8f764e6..3710c53 100755 --- a/install-go.pl +++ b/install-go.pl @@ -119,37 +119,45 @@ sub resolve_target my($vreg, $last_minor); if ($target =~ /^\d+\.\d+(?:\.\d+)?\z/a) { - $vreg = quotemeta $target; + # exact match expected } elsif ($target =~ /^(\d+\.\d+)\.x\z/a) { $target = $1; + $vreg = quotemeta($target) . '(?:\.([0-9]+))?'; + $vreg = qr/^go$vreg\z/; + $last_minor = -1; } else { die "Bad target $target, should be 1.12 or 1.12.1 or 1.12.x\n" } - $vreg = qr/^go$vreg\z/; my $r = http_get('https://go.googlesource.com/go/+refs/tags?format=JSON'); $r->{success} or die "Cannot retrieve tags: $r->{status} $r->{reason}\n$r->{content}\n"; + my $versions = decode_json($r->{content} =~ s/^[^{]+//r); + my $found; - foreach (keys %{decode_json($r->{content} =~ s/^[^{]+//r)}) + if (defined $vreg) { - if (/$vreg/) + foreach (keys %$versions) { - $last_minor // return ($target, undef); # OK found - - if ($last_minor < ($1 // 0)) + if (/$vreg/ and $last_minor < ($1 // 0)) { $last_minor = $1; $found = 1; } } } + else + { + # exact match expected + $found = exists $versions->{"go$target"}; + } + $found or die "Version $target not found\n"; return ($target, $last_minor);