diff options
author | Slack Coder <slackcoder@server.ky> | 2025-05-09 13:28:49 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2025-05-14 17:54:10 -0500 |
commit | 672df60f0cd3659aa17267c833c6dda4b248c7d2 (patch) | |
tree | cc625ceefd99de108ad576ab266574d1233d9c72 /SBO-Lib/lib/SBO/Lib/Download.pm | |
parent | 6dcbba8e9450d4a312880dea8e91ee4d58a3af0d (diff) | |
download | sbotools2-672df60f0cd3659aa17267c833c6dda4b248c7d2.tar.xz |
Use Perl's URI library code to properly parse and handle SlackBuild links.
Diffstat (limited to 'SBO-Lib/lib/SBO/Lib/Download.pm')
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Download.pm | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/SBO-Lib/lib/SBO/Lib/Download.pm b/SBO-Lib/lib/SBO/Lib/Download.pm index ab65765..eb8bfdc 100644 --- a/SBO-Lib/lib/SBO/Lib/Download.pm +++ b/SBO-Lib/lib/SBO/Lib/Download.pm @@ -11,6 +11,7 @@ use SBO::Lib::Repo qw/ $distfiles /; use SBO::Lib::Info qw/ get_download_info /; use Digest::MD5; +use URI (); use Exporter 'import'; our @EXPORT_OK = qw{ @@ -162,10 +163,14 @@ sub get_distfile { my $fail = {}; if ($config{FALLBACK_ARCHIVE} ne 'FALSE') { + my $uri = URI->new($link); + my @segments = $uri->path_segments(); + my $filename = $segments[-1]; + push(@links, sprintf( "%s/by-md5/%s/%s/%s/%s", $config{FALLBACK_ARCHIVE}, - substr($info_md5, 0, 1), substr($info_md5, 1, 1), $info_md5, _get_fname($link), + substr($info_md5, 0, 1), substr($info_md5, 1, 1), $info_md5, $filename, )); } @@ -223,8 +228,12 @@ C<$link>. sub get_filename_from_link { script_error('get_filename_from_link requires an argument') unless @_ == 1; - my $filename = _get_fname(shift); - return undef unless defined $filename; + + my $uri = URI->new(shift); + my @segments = $uri->path_segments(); + my $filename = $segments[-1]; + + return undef unless length($filename); return "$distfiles/$filename"; } @@ -296,14 +305,4 @@ sub verify_distfile { return $info_md5 eq $md5sum ? 1 : 0; } -# given a link, grab the filename from it and prepend $distfiles -sub _get_fname { - my $fn = shift; - my $regex = qr#/([^/]+)$#; - my ($filename) = $fn =~ $regex; - $filename =~ s/%2B/+/g if $filename; - return $filename; - -} - 1; |