Created
September 5, 2018 16:21
-
-
Save nicomen/402a091149bfc81cb8df1a9d9f3d0ba3 to your computer and use it in GitHub Desktop.
getting correct versions of possible valid dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub _get_deb_candidates { | |
my ( $self, $wanted_pkgs) = @_; | |
$self->log('._deb_deb_candidates')->logdie("Please provide packages to search for") unless $wanted_pkgs; | |
my $candidates; | |
for my $wanted_pkg (keys %{$wanted_pkgs}) { | |
my $pkg_pattern = $self->_get_pkg_alternatives_pattern($wanted_pkg); | |
my $packages = $self->dpkg->get_available_versions($pkg_pattern); | |
my $versions = { map { my $pkg_name = $_; map { $_ => $pkg_name } keys %{ $packages->{$pkg_name} || {} } } keys %{ $packages || {} } }; | |
my $version_has_epoch = 0; | |
for my $version (keys %{$versions}) { | |
# If we found a version with epoch | |
if ($version =~ m{ \A (\d+): }gmx) { | |
# and the epoch is bigger than what we already have found, let's store it | |
$version_has_epoch = $1 if ($1 > $version_has_epoch); | |
} | |
} | |
my $wanted_version = $wanted_pkgs->{$wanted_pkg} || 0; | |
# Add epoch to wanted version if existing packages has started using epoch | |
if ($wanted_version && $version_has_epoch) { | |
# replace existing epoch, or prepend it. | |
if ($wanted_version =~ m{ \A (\d+): }gmx) { | |
if ($1 < $version_has_epoch) { | |
$wanted_version =~ s{ \A (\d+): }{$version_has_epoch}gmx; | |
} | |
} else { | |
$wanted_version = "$version_has_epoch:$wanted_version"; | |
} | |
} | |
$candidates->{$wanted_pkg} = { | |
wanted_version => $wanted_version, | |
pkg_pattern => $pkg_pattern, | |
versions => { map { | |
$_ => { | |
wanted_version => $wanted_version, | |
version => $_, | |
pkg_name_version => $versions->{$_} . ($wanted_version ? " (>= $wanted_version)" : ''), | |
apt_get_install_line => $versions->{$_} . ($wanted_version ? "=$_" : ''), | |
} | |
} grep { $_ ne '(null)' } keys %{$versions} }, | |
}; | |
} | |
return $candidates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment