Hello,

I have significantly reworked and simplified the patch:

- avoid creating several files at the same time
- always create usr/lib/choose-mirror/port_architecture to make rules
  much simpler.
- use a single variable $archive that normally contains 'archive' but
  can be set to 'ports'.

so that we end up only doing this in mirrorlist:

- set $archive to 'archive' by default
- loop for the architecture in a Ports-architecture field, if so set
  $archive to 'ports'.
- replace 'archive' with $archive in the strings.
- create the port_architecture containing either 0 or 1 when requested to

I tried to build with on amd64 and on hurd-i386, I am getting the expected 
results:
- /usr/lib/choose-mirror/port_architecture contains 0 on amd64 and 1 on
hurd-i386.
- The choose-mirror binary contains the full mirror list on amd64, it
contains only deb.debian.org on hurd-i386.

Does anybody think of anything else I should check before I commit this?

Samuel
diff --git a/Makefile b/Makefile
index b4a7ecc..e10c167 100644
--- a/Makefile
+++ b/Makefile
@@ -86,7 +86,10 @@ debian/httpslist-countries: $(MASTERLIST) debian/iso_3166.tab
 debian/ftplist-countries: $(MASTERLIST) debian/iso_3166.tab
        ./mirrorlist ftplist $^
 
-debian/choose-mirror-bin.templates: $(MASTERLIST) $(templates) 
debian/httplist-countries debian/httpslist-countries debian/ftplist-countries 
debian/iso_3166.tab
+debian/port_architecture: $(MASTERLIST) debian/iso_3166.tab
+       ./mirrorlist port_architecture $^
+
+debian/choose-mirror-bin.templates: $(MASTERLIST) $(templates) 
debian/httplist-countries debian/httpslist-countries debian/ftplist-countries 
debian/iso_3166.tab debian/port_architecture
        # Grab ISO codes from iso-codes package
        ./get-iso-codes
        # Build the templates
@@ -132,6 +135,7 @@ clean:
        rm -f demo demo.templates
        rm -rf debian/iso-codes/ debian/pobuild*/
        rm -f debian/iso_3166.tab
+       rm -f debian/port_architecture
 
 reallyclean: clean
        rm -f debian/choose-mirror-bin.templates
diff --git a/debian/choose-mirror-bin.install b/debian/choose-mirror-bin.install
index 7a92821..568306a 100644
--- a/debian/choose-mirror-bin.install
+++ b/debian/choose-mirror-bin.install
@@ -1 +1,2 @@
 choose-mirror bin
+debian/port_architecture usr/lib/choose-mirror
diff --git a/mirrorlist b/mirrorlist
index 0a811b2..f55e315 100755
--- a/mirrorlist
+++ b/mirrorlist
@@ -104,12 +104,28 @@ foreach my $id (0..$#data) {
        $data[$id]->{rating}=$rating;
 }
 
+# Defaults for released architectures
+my $archive = 'archive';
+
+# Is $hostarch a port architecture ?
+# Such architectures appear in a Ports-architecture: field
+foreach my $id (0..$#data) {
+       if (exists $data[$id]->{'ports-architecture'}) {
+               my @arches = split ' ', $data[$id]->{'ports-architecture'};
+               my %arches = map { $_ => 1 } @arches;
+               if (exists $arches{$hostarch} or exists $arches{'!'.$hostarch}) 
{
+                       $archive = 'ports';
+                       last;
+               }
+       }
+}
+
 # Filter out mirrors that don't carry the target architecture.
 my @newdata;
 foreach my $id (0..$#data) {
-       if (exists $data[$id]->{'archive-architecture'} &&
-           $data[$id]->{'archive-architecture'} ne "any") {
-               my @arches = split ' ', $data[$id]->{'archive-architecture'};
+       if (exists $data[$id]->{"$archive-architecture"} &&
+           $data[$id]->{"$archive-architecture"} ne "any") {
+               my @arches = split ' ', $data[$id]->{"$archive-architecture"};
                if (grep /^!/, @arches) {
                        my %notarches = map { substr($_, 1) => 1 } grep /^!/, 
@arches;
                        next if exists $notarches{$hostarch};
@@ -126,7 +142,7 @@ if ($type =~ /(.*)list/) {
        my $type=$1;
        open (LIST, ">debian/${type}list-countries") or die 
"debian/${type}list-countries: $!";
        foreach my $id (0..$#data) {
-               next unless exists $data[$id]->{"archive-$type"} and
+               next unless exists $data[$id]->{"$archive-$type"} and
                                    exists $data[$id]->{country};
                my $cc = $data[$id]->{country};
                die "Error: country code '$cc' does not occur in iso-3166 table"
@@ -138,6 +154,15 @@ if ($type =~ /(.*)list/) {
        }
        close LIST;
 }
+elsif ($type eq "port_architecture") {
+       open(OUT,"> debian/port_architecture") || die "Unable to write 
debian/port_architecture\n";
+       if ($archive eq 'ports') {
+               print OUT "1\n";
+       } else {
+               print OUT "0\n";
+       }
+       close OUT;
+}
 else {
        open (OUT, ">mirrors_$type.h") or die "mirrors_$type.h: $!";
        print OUT "/* Automatically generated; do not edit. */\n";
@@ -154,13 +179,13 @@ else {
                else {
                        $cc=$q.$data[$id]->{country}.$q;
                }
-               next unless exists $data[$id]->{"archive-$type"} and defined 
$cc;
-               if (! exists $data[$id]->{'archive-architecture'}) {
-                       print STDERR "warning: missing archive-architecture for 
mirror ".$data[$id]->{site}."; assuming it contains all architectures.\n";
+               next unless exists $data[$id]->{"$archive-$type"} and defined 
$cc;
+               if (! exists $data[$id]->{"$archive-architecture"}) {
+                       print STDERR "warning: missing $archive-architecture 
for mirror ".$data[$id]->{site}."; assuming it contains all architectures.\n";
                }
                print OUT "\t{",
                          join(", ", $q.$data[$id]->{site}.$q, $cc,
-                               $q.$data[$id]->{"archive-$type"}.$q),
+                               $q.$data[$id]->{"$archive-$type"}.$q),
                          "},\n";
        }
        print OUT "\t{NULL, NULL, NULL}\n";

Reply via email to