From 4ec9e1c470394e99e21ce669fb42d853c950dd94 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 2 Apr 2024 13:19:47 -0400 Subject: sbofixinfo: fix non-canonical github archive/ URLs. --- sbofixinfo | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'sbofixinfo') diff --git a/sbofixinfo b/sbofixinfo index a1eff12..7b1e9ed 100755 --- a/sbofixinfo +++ b/sbofixinfo @@ -83,6 +83,28 @@ original and 'corrected' key names using your own eyeballs and brain. If there is no PRGNAM, it will be generated from the .info file's name (minus the I<.info> extension). +=item - + +Github archive/ download URLs will be "canonized". This means URLs of these +forms: + + https://github.com/user/project/archive/v1.2.3.tar.gz + https://github.com/user/project/archive/refs/tags/v1.2.3.tar.gz + https://github.com/user/project/archive/1.2.3.tar.gz + https://github.com/user/project/archive/refs/tags/1.2.3.tar.gz + +...will be rewritten as: + + https://github.com/user/project/archive//project-1.2.3.tar.gz + +..where will be v1.2.3 or 1.2.3, depending on whether the "v" was in the +original URL. + +The purpose of this is to give a stable download filename, which won't vary depending +on whether a browser or wget/curl is used to download the file. + +See https://slackbuilds.org/GITHUB_URLs.txt for more information. + =back B doesn't attempt to detect any other errors or dubious @@ -138,6 +160,24 @@ B(1), B(1), B(1), B(8), B(1) EMAIL }; +sub fix_github_url { + my $url = shift; + return $url unless $url =~ m,/archive/,; + + $url =~ s,refs/tags/,,; + + (my $proto, undef, undef, $user, $proj, undef, $tag, $filename) = split /\//, $url; + return $url if defined $filename; + + return $url unless $tag =~ s,\.tar\.gz$,,; + my $ver = $tag; + $ver =~ s,^v(\d),$1,; + + $url = "https://github.com/$user/$proj/archive/$tag/$proj-$ver.tar.gz"; + return $url; +} + +## main() $arg0 = @ARGV ? $ARGV[0] : undef; for($arg0) { defined || last; @@ -303,6 +343,22 @@ sub fix_info { } close $fh; + # 20240331 bkw: fix github URLs, if needed. + for my $key (qw/DOWNLOAD DOWNLOAD_x86_64/) { + if($info{$key}) { + my @urls = split " ", $info{$key}; + my @newurls; + for my $url (@urls) { + my $newurl = $url; + if($url =~ m,https://github.com/,) { + $newurl = fix_github_url($url); + } + push @newurls, $newurl; + } + $info{$key} = join " ", @newurls; + } + } + system("mv $file $file.bak"); open $fh, ">$file" or do { -- cgit v1.2.3