diff options
author | Florian Pritz <bluewind@xinu.at> | 2018-11-19 00:57:11 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2018-11-19 00:57:11 +0100 |
commit | df8f04661d46f03f7c2dd4041c520c479179ed8a (patch) | |
tree | 10c42c6537cc0ec46877412e1997b91ff04a94bb /lib/App | |
parent | a01c7719bc535092ce3a6e83bb26159d3f117d72 (diff) | |
download | App-ArchLinux-PackagerTools-df8f04661d46f03f7c2dd4041c520c479179ed8a.tar.gz App-ArchLinux-PackagerTools-df8f04661d46f03f7c2dd4041c520c479179ed8a.tar.xz |
Batch calls to expac for performance
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App')
-rw-r--r-- | lib/App/ArchLinux/PackagerTools.pm | 4 | ||||
-rw-r--r-- | lib/App/ArchLinux/PackagerTools/Pacman.pm | 68 |
2 files changed, 69 insertions, 3 deletions
diff --git a/lib/App/ArchLinux/PackagerTools.pm b/lib/App/ArchLinux/PackagerTools.pm index 0a45bb8..cfc2f01 100644 --- a/lib/App/ArchLinux/PackagerTools.pm +++ b/lib/App/ArchLinux/PackagerTools.pm @@ -80,8 +80,10 @@ older) and the CPAN distribution. method get_updateable_packages($distribution_names) { my @packages; + my $repo_versions = $self->{deps}->{pacman}->get_perl_distribution_versions($distribution_names); for my $dist_name ($distribution_names->@*) { - my $repo_version = $self->{deps}->{pacman}->get_perl_distribution_version($dist_name); + #my $repo_version = $self->{deps}->{pacman}->get_perl_distribution_version($dist_name); + my $repo_version = $repo_versions->{$dist_name}; my $dist = $self->{deps}->{cpan}->get_dist($dist_name); if ($self->{deps}->{cpan}->is_newer_version_available($dist_name, $repo_version)) { $log->infof('New version available for dist \'%s\': %s', $dist_name, $dist->{version}); diff --git a/lib/App/ArchLinux/PackagerTools/Pacman.pm b/lib/App/ArchLinux/PackagerTools/Pacman.pm index ec4f991..b9fe988 100644 --- a/lib/App/ArchLinux/PackagerTools/Pacman.pm +++ b/lib/App/ArchLinux/PackagerTools/Pacman.pm @@ -131,6 +131,30 @@ method get_package_version($pkgname) { return $version; } +=head3 get_packages_versions + + my $versions = $pacman->get_packages_versions($package_names); + +Return a hash that maps each package name to the version of that package in the +pacman repository. + +=cut + +method get_packages_versions($package_names) { + my %versions; + + open my $fh, '-|', qw(expac -S -1), '%n %v', '--', $package_names->@*; + while (<$fh>) { + my ($pkgname, $version) = split /\s/; + $versions{$pkgname} = $version; + $log->debugf("Package '%s' has version '%s' in repository", $pkgname, $version); + } + if ($package_names->@* != keys %versions) { + croak $log->error("Failed to find version for all packages. Got %d packages and %d versions were detected", scalar($package_names->@*), scalar(keys %versions)); + } + return \%versions; +} + =head3 get_perl_pkgname my $pkgname = $pacman->get_perl_pkgname($dist_name); @@ -162,12 +186,52 @@ pacman-specific information from the pacman's package version. method get_perl_distribution_version($dist_name) { my $pkgname = $self->get_perl_pkgname($dist_name); my $version = $self->get_package_version($pkgname); + $version = $self->_clean_version($version); + + $log->tracef("Found version '%s' for package '%s'", $version, $pkgname); + return $version; +} + +=head3 get_perl_distribution_versions + + my $distribution_names = ['App::ArchLinux::PackagerTools', 'DBI']; + my $versions = $pacman->get_perl_distribution_versions($distribution_names); + print $versions->{'DBI'}; # prints "1.642" + +Return a hash that maps a CPAN distribution name to the respective version of +the CPAN distribution of the pacman repository package. + +=cut + +method get_perl_distribution_versions($distribution_names) { + my %pkgname_dist; + for my $dist_name ($distribution_names->@*) { + $pkgname_dist{$self->get_perl_pkgname($dist_name)} = $dist_name; + } + + my $versions = $self->get_packages_versions([keys %pkgname_dist]); + my %dist_versions; + for my $key (keys $versions->%*) { + $dist_versions{$pkgname_dist{$key}} = $self->_clean_version($versions->{$key}); + $log->debugf("Cleaned version of package '%s' is now '%s'", $key, $versions->{$key}); + } + return \%dist_versions; + +} + +=head3 _clean_version + + my $version = $self->_clean_version($version); + +Strip pacman-specific information (pkgrel, epoch) from a version string. + +=cut + +method _clean_version($version) { # remove pkgrel $version =~ s/-\d+(\.\d+)?$//; # remove epoch $version =~ s/^\d+://; - - $log->tracef("Found version '%s' for package '%s'", $version, $pkgname); return $version; } |