diff options
-rw-r--r-- | lib/Youri/Repository/Mandriva_upload.pm | 98 |
1 files changed, 73 insertions, 25 deletions
diff --git a/lib/Youri/Repository/Mandriva_upload.pm b/lib/Youri/Repository/Mandriva_upload.pm index bfc4935..381aee5 100644 --- a/lib/Youri/Repository/Mandriva_upload.pm +++ b/lib/Youri/Repository/Mandriva_upload.pm @@ -276,6 +276,9 @@ sub _get_section { my ($self, $package, $target, $user_context, $app_context) = @_; my $name = $package->get_name(); + my $cname = $package->get_canonical_name(); + my $version = $package->get_version(); + my $release = $package->get_release(); my $section = $user_context->{section}; my $media = $self->_get_media_config($target); my $arch = $package->get_arch(); @@ -293,7 +296,7 @@ sub _get_section { $section = "debug_$section" } - # if section is provided, check this one is defined + # if have section already, check if it exists, and may return immediately if ($section) { print "Using requested section $section\n"; if ($media->{$arch}{$section}) { @@ -302,50 +305,95 @@ sub _get_section { die "FATAL youri: unknown section $section for target $target for arch $arch\n" } } - # try to find section automatically + # else, try to find section automatically + + # pattern for search of src package with specific version-release, + # should be searched first, because we prefer to find the precise + # section a package is already in + my $specific_source_pattern = PACKAGE_CLASS->get_pattern( + $cname, + $version, + $release, + 'src' + ); my $source_pattern = PACKAGE_CLASS->get_pattern( - $package->get_canonical_name(), + $cname, undef, undef, 'src' ); + # if a media has no source media configured, or if it is a debug + # package, we search in binary media + + # pattern for search when a binary media has no src media configured + my $specific_binary_pattern = PACKAGE_CLASS->get_pattern( + $name, + $version, + $release, + $arch + ); + + # last resort pattern: previous existing binary packages my $binary_pattern = PACKAGE_CLASS->get_pattern( - $package->get_name(), - undef, - undef, - $arch + $name, + undef, + undef, + $arch ); - # for each potential section, try to match - # a suitable source patten in source directory - # a suitable binary patten in binary directory + # first try to find section for the specific version, as it is possibly already there + print "Looking for package $name with version $version-$release\n"; foreach my $m (keys %{$media->{$arch}}) { - # do not use testing by default - next if $m =~ /testing/; - next unless - ($media->{src}{$m} && - $self->get_files( - '', - $media->{src}{$m}, - $source_pattern - )) || $self->get_files( - '', - $media->{$arch}{$m}, - $binary_pattern - ); - print "Section is $m\n"; + print " .. section '$m' path '".$media->{$arch}{$m}."'\n" if $self->{_verbose}; + # - prefer source for non-debug packages, use binary if there is no source media configured + # - debug packages must be searched in binary medias, due to their + # src section != binary section; NOTE: should/need we search in + # src medias and add the 'debug_' prefix? + if (!$package->is_debug() && $media->{src}{$m}) { + next unless $self->get_files('', $media->{src}{$m}, $specific_source_pattern); + } else { + next unless $self->get_files('', $media->{$arch}{$m}, $specific_binary_pattern); + } $section = $m; last; } - print STDERR "Can't guess destination: section missing, defaulting to contrib/release\n" unless $section; + # if still not found, try finding any version of the package in a + # /release subsection (safe default: /release is default for cooker, + # should be locked for released distros, and we don't risk wrongly + # choosing /backports, /testing, or /updates); + if (!$section) { + # debug packages should be found by previous specific version search + # NOTE: as above, should/need we search here and add the 'debug_' prefix? + if ($package->is_debug()) { + die "FATAL: debug package $name with version $version-$release not found.\n" + } + + print "Warning: Looking for any section with a package $name of any version\n"; + foreach my $m (keys %{$media->{$arch}}) { + print " .. section '$m' path '".$media->{$arch}{$m}."'\n" if $self->{_verbose}; + next if $m !~ /release/; + # - prefer source + if ($media->{src}{$m}) { + next unless $self->get_files('', $media->{src}{$m}, $source_pattern); + } else { + next unless $self->get_files('', $media->{$arch}{$m}, $binary_pattern); + } + $section = $m; + last; + } + } + + print STDERR "Warning: Can't guess destination: section missing, defaulting to contrib/release\n" unless $section; $section ||= 'contrib/release'; # next time we don't need to search everything again $self->{packages}{$file}{section} = $section; + print "Section is '$section'.\n"; + return $section; } |