diff --git a/modules/ksb/Updater/Git.pm b/modules/ksb/Updater/Git.pm index 6ef4422..a97c52b 100644 --- a/modules/ksb/Updater/Git.pm +++ b/modules/ksb/Updater/Git.pm @@ -16,7 +16,6 @@ use File::Basename; # basename use File::Spec; # tmpdir use POSIX qw(strftime); use List::Util qw(first); -use URI; use ksb::IPC::Null; @@ -454,6 +453,18 @@ sub _determinePreferredCheckoutSource return ($checkoutSource, $sourceTypeRef->[1]); } +# Splits a URI up into its component parts. Taken from +# http://search.cpan.org/~ether/URI-1.67/lib/URI.pm +# Copyright Gisle Aas under the following terms: +# "This program is free software; you can redistribute it and/or modify it +# under the same terms as Perl itself." +sub _splitUri +{ + my($scheme, $authority, $path, $query, $fragment) = + $_[0] =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|; + return ($scheme, $authority, $path, $query, $fragment); +} + # Attempts to download and install a git snapshot for the given ksb::Module. # This requires the module to have the '#snapshot-tarball' option set, # normally done after KDEXMLReader is used to parse the projects.kde.org @@ -488,7 +499,7 @@ sub installGitSnapshot info ("\tDownloading git snapshot for g[$module]"); - my $filename = basename(URI->new($tarball)->path()); + my $filename = basename( (_splitUri($tarball))[2] ); my $tmpdir = File::Spec->tmpdir() // "/tmp"; $filename = "$tmpdir/$filename"; # Make absolute diff --git a/modules/ksb/Util.pm b/modules/ksb/Util.pm index b9e77d9..4f5c006 100644 --- a/modules/ksb/Util.pm +++ b/modules/ksb/Util.pm @@ -15,7 +15,7 @@ use File::Find; use Cwd qw(getcwd); use Errno qw(:POSIX); use Digest::MD5; -use LWP::UserAgent; +use HTTP::Tiny; use ksb::Debug; use ksb::Version qw(scriptVersion); @@ -598,31 +598,29 @@ sub download_file { my ($url, $filename, $proxy) = @_; - my $ua = LWP::UserAgent->new(timeout => 30); my $scriptVersion = scriptVersion(); - - # Trailing space adds the appropriate LWP info since the resolver is not - # my custom coding anymore. - $ua->agent("kdesrc-build/$scriptVersion "); + my %opts = ( + # Trailing space adds lib version info + agent => "kdesrc-build/$scriptVersion ", + timeout => 30, + ); if ($proxy) { - whisper ("Using proxy $proxy for FTP, HTTP downloads"); - $ua->proxy(['http', 'ftp'], $proxy); - } - else { - whisper ("Using proxy as determined by environment"); - $ua->env_proxy(); + whisper ("Using proxy $proxy for HTTP downloads"); + $opts{proxy} = $proxy; } + my $http_client = HTTP::Tiny->new(%opts); + whisper ("Downloading g[$filename] from g[$url]"); - my $response = $ua->mirror($url, $filename); + my $response = $http_client->mirror($url, $filename); - # LWP's mirror won't auto-convert "Unchanged" code to success, so check for - # both. - return 1 if $response->code == 304 || $response->is_success; + return 1 if $response->{success}; + $response->{reason} .= " $response->{content}" if $response->{status} == 599; error ("Failed to download y[b[$url] to b[$filename]"); - error ("Result was: y[b[" . $response->status_line . "]"); + error ("Result was: y[b[$response->{status} $response->{reason}]"); + return 0; }