]> git.donarmstrong.com Git - debbugs.git/blobdiff - examples/debian/versions/build-versions-db
IO::Uncompress is too slow; use open_compressed_file
[debbugs.git] / examples / debian / versions / build-versions-db
index 16eb5369f2ba47c8aa4173caab73cf5f88a27760..10fb32c141ff65af77377c3f0e468699543a3875 100755 (executable)
@@ -55,19 +55,15 @@ Display this manual.
 
 use vars qw($DEBUG);
 use Debbugs::Versions::Dpkg;
-use IO::Uncompress::AnyUncompress;
 use MLDBM qw(DB_File Storable);
 use Fcntl;
 
 my %options = (debug           => 0,
                help            => 0,
                man             => 0,
-               compprefix      => '',
               );
 
 GetOptions(\%options,
-           'hostname=s',
-           'compprefix=s',
            'debug|d+','help|h|?','man|m');
 
 pod2usage() if $options{help};
@@ -76,9 +72,6 @@ pod2usage({verbose=>2}) if $options{man};
 $DEBUG = $options{debug};
 
 my @USAGE_ERRORS;
-if (not defined $options{hostname}) {
-    push @USAGE_ERRORS,"You must provide a hostname";
-}
 
 if (not @ARGV >= 4) {
     push @USAGE_ERRORS,
@@ -105,10 +98,27 @@ tie %db, "MLDBM", $versions, O_CREAT|O_RDWR, 0664
 tie %db2, "MLDBM", $versions_time,O_CREAT|O_RDWR, 0664
      or die "tie $versions_time failed: $!";
 
+sub open_compressed_file {
+    my ($file) = @_;
+    my $fh;
+    my $mode = '<:encoding(UTF-8)';
+    my @opts;
+    if ($file =~ /\.gz$/) {
+       $mode = '-|:encoding(UTF-8)';
+       push @opts,'gzip','-dc';
+    }
+    if ($file =~ /^\.xz$/) {
+       $mode = '-|:encoding(UTF-8)';
+       push @opts,'xz','-dc';
+    }
+    open($fh,$mode,@opts,$file);
+    return $fh;
+}
+
 # Read Package, Version, and Source fields from a Packages.gz file.
 sub read_packages {
     my ($packages, $component,$arch,$dist) = @_;
-    my $PACKAGES = IO::Uncompress::AnyUncompress->new($packages) or
+    my $PACKAGES = open_compressed_file($packages)
         die "Unable to open $packages for reading: $!";
     local $_;
     local $/ = '';     # paragraph mode
@@ -157,7 +167,6 @@ for my $suite (@suites) {
        # debian-installer is really a section rather than a component
        # (ugh).
        (my $viscomponent = $component) =~ s[/.*][];
-       $viscomponent = $options{compprefix} . $viscomponent;
 
        my $sources = (grep { -f $_ } glob "$suitedir/$component/source/Sources.*")[0];
        next unless defined $sources;