2 # Debian.pl: Frontend to debian contents and packages files
4 # Version: v0.8 (20000918)
12 # format: "alias=real".
14 my $defaultdist = "woody";
16 "unstable" => "woody",
18 "incoming" => "incoming",
19 "slink" => "archive-2.1",
20 "hamm" => "archive-2.0",
21 "rex" => "archive-1.?",
22 "bo" => "archive-1.?",
26 "debian/Contents-##DIST-i386.gz" =>
27 "ftp://ftp.us.debian.org".
28 "/debian/dists/##DIST/Contents-i386.gz", #woody = BROKEN
30 "debian/Contents-##DIST-i386-non-US.gz" =>
31 "ftp://ftp.ca.debian.org".
32 "/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
36 "debian/Packages-##DIST-main-i386.gz" =>
37 "ftp://ftp.us.debian.org".
38 "/debian/dists/##DIST/main/binary-i386/Packages.gz",
39 "debian/Packages-##DIST-contrib-i386.gz" =>
40 "ftp://ftp.us.debian.org".
41 "/debian/dists/##DIST/contrib/binary-i386/Packages.gz",
42 "debian/Packages-##DIST-non-free-i386.gz" =>
43 "ftp://ftp.us.debian.org".
44 "/debian/dists/##DIST/non-free/binary-i386/Packages.gz",
46 "debian/Packages-##DIST-non-US-main-i386.gz" =>
47 "ftp://ftp.ca.debian.org".
48 "/debian-non-US/dists/##DIST/non-US/main/binary-i386/Packages.gz",
49 "debian/Packages-##DIST-non-US-contrib-i386.gz" =>
50 "ftp://ftp.ca.debian.org".
51 "/debian-non-US/dists/##DIST/non-US/contrib/binary-i386/Packages.gz",
52 "debian/Packages-##DIST-non-US-non-free-i386.gz" =>
53 "ftp://ftp.ca.debian.org".
54 "/debian-non-US/dists/##DIST/non-US/non-free/binary-i386/Packages.gz",
58 ### COMMON FUNCTION....
59 #######################
62 # Usage: &DebianDownload(%hash);
64 my ($dist, %urls) = @_;
65 my $refresh = $main::param{'debianRefreshInterval'} * 60 * 60 * 24;
70 &main::status("Debian: creating debian dir.");
71 mkdir("debian/",0755);
78 foreach $file (keys %urls) {
79 my $url = $urls{$file};
80 $url =~ s/##DIST/$dist/g;
81 $file =~ s/##DIST/$dist/g;
85 my $last_refresh = (stat($file))[9];
86 $update++ if (time() - $last_refresh > $refresh);
91 next unless ($update);
93 &main::DEBUG("announce == $announce.");
94 if ($good + $bad == 0 and !$announce) {
95 &main::status("Debian: Downloading files for '$dist'.");
96 &main::msg($main::who, "Updating debian files... please wait.");
100 if (exists $main::debian{$url}) {
101 &main::DEBUG("2: ".(time - $main::debian{$url})." <= $refresh");
102 next if (time() - $main::debian{$url} <= $refresh);
103 &main::DEBUG("stale for url $url; updating!");
106 if ($url =~ /^ftp:\/\/(.*?)\/(\S+)\/(\S+)$/) {
107 my ($host,$path,$thisfile) = ($1,$2,$3);
109 # error internally to ftp.
110 # hope it doesn't do anything bad.
111 if ($file =~ /Contents-woody-i386-non-US/) {
112 &main::DEBUG("Skipping Contents-woody-i386-non-US.");
113 $file =~ s/woody/potato/;
114 $path =~ s/woody/potato/;
118 if (!&main::ftpGet($host,$path,$thisfile,$file)) {
119 &main::DEBUG("deb: down: ftpGet($host,$path,$thisfile,$file) == BAD.");
125 &main::DEBUG("deb: down: ftpGet: !file");
130 if ($file =~ /Contents-potato-i386-non-US/) {
131 &main::DEBUG("hack: using potato's non-US contents for woody.");
132 system("cp debian/Contents-potato-i386-non-US.gz debian/Contents-woody-i386-non-US.gz");
135 &main::DEBUG("deb: download: good.");
139 &main::ERROR("Debian: invalid format of url => ($url).");
146 &generateIndex($dist);
149 return -1 unless ($bad); # no download.
150 &main::DEBUG("DD: !good and bad($bad). :(");
155 ###########################
156 # DEBIAN CONTENTS SEARCH FUNCTIONS.
160 # Usage: &searchContents($query);
162 my ($dist, $query) = &getDistroFromStr($_[0]);
163 &main::status("Debian: Contents search for '$query' on $dist.");
166 $dccsend++ if ($query =~ s/^dcc\s+//i);
168 # $query = $query.'(\.so\.)?([.[[:digit:]]+\.]+)?$';
170 $query =~ s/\\([\^\$])/$1/g; # hrm?
171 $query =~ s/^\s+|\s+$//g;
172 $query =~ s/\*/\\S*/g; # does it even work?
174 if (!&main::validExec($query)) {
175 &main::msg($main::who, "search string looks fuzzy.");
179 if ($dist eq "incoming") { # nothing yet.
180 &main::DEBUG("sC: dist = 'incoming'. no contents yet.");
183 my %urls = &fixDist($dist, %urlcontents);
184 # download contents file.
185 &main::DEBUG("deb: download 1.");
186 if (!&DebianDownload($dist, %urls)) {
187 &main::WARN("Debian: could not download files.");
192 my $start_time = &main::gettimeofday();
198 ### TODO: search properly if /usr/bin/blah is done.
199 if ($query =~ s/\$$//) {
200 &main::DEBUG("search-regex found.");
201 $search = "$query\[ \t]";
202 } elsif ($query =~ s/^\^//) {
203 &main::DEBUG("front marker regex found.");
207 $search = "$query.*\[ \t]";
211 foreach (keys %urlcontents) {
214 next unless ( -f $_);
218 if (!scalar @files) {
219 &main::ERROR("sC: no files?");
220 &main::msg($main::who, "failed.");
224 my $files = join(' ', @files);
226 &main::status("search regex => '$search'.");
227 open(IN,"zegrep -h '$search' $files |");
229 if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) {
230 my ($file,$package) = ("/".$1,$2);
231 if ($query =~ /\//) {
232 next unless ($file =~ /\Q$query\E/);
234 my ($basename) = $file =~ /^.*\/(.*)$/;
235 next unless ($basename =~ /\Q$query\E/);
237 next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
238 next if ($front and $file !~ /^\/\Q$query\E/);
240 $contents{$package}{$file} = 1;
248 ### send results with dcc.
250 if (exists $main::dcc{'SEND'}{$main::who}) {
251 &main::msg($main::who, "DCC already active!");
255 if (!scalar %contents) {
256 &main::msg($main::who,"search returned no results.");
264 my $file = "temp/$main::who.txt";
265 if (!open(OUT,">$file")) {
266 &main::ERROR("Debian: cannot write file for dcc send.");
270 foreach $pkg (keys %contents) {
271 foreach (keys %{$contents{$pkg}}) {
272 # TODO: correct padding.
273 print OUT "$_\t\t\t$pkg\n";
278 &main::shmWrite($main::shm, "DCC SEND $main::who $file");
283 &main::status("Debian: $found contents results found.");
286 foreach $pkg (keys %contents) {
287 my @tmplist = &main::fixFileList(keys %{$contents{$pkg}});
288 my @sublist = sort { length $a <=> length $b } @tmplist;
290 pop @sublist while (scalar @sublist > 3);
292 $pkg =~ s/\,/\037\,\037/g; # underline ','.
293 push(@list, "(". join(', ',@sublist) .") in $pkg");
295 # sort the total list from shortest to longest...
296 @list = sort { length $a <=> length $b } @list;
298 # show how long it took.
299 my $delta_time = &main::gettimeofday() - $start_time;
300 &main::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
302 my $prefix = "Debian Search of '$query' ";
303 if (scalar @list) { # @list.
304 &main::performStrictReply( &main::formListReply(0, $prefix, @list) );
306 &main::DEBUG("ok, !\@list, searching desc for '$query'.");
312 # Usage: &searchAuthor($query);
314 my ($dist, $query) = &getDistroFromStr($_[0]);
315 &main::DEBUG("searchAuthor: dist => '$dist', query => '$query'.");
316 $query =~ s/^\s+|\s+$//g;
319 my $start_time = &main::gettimeofday();
320 &main::status("Debian: starting author search.");
323 my ($bad,$good) = (0,0);
324 my %urls = %urlpackages;
326 foreach (keys %urlpackages) {
338 &main::DEBUG("good = $good, bad = $bad...");
340 if ($good == 0 and $bad != 0) {
341 my %urls = &fixDist($dist, %urlpackages);
342 &main::DEBUG("deb: download 2.");
343 if (!&DebianDownload($dist, %urls)) {
344 &main::ERROR("Debian(sA): could not download files.");
349 my (%maint, %pkg, $package);
350 open(IN,"zegrep -h '^Package|^Maintainer' $files |");
352 if (/^Package: (\S+)$/) {
354 } elsif (/^Maintainer: (.*) \<(\S+)\>$/) {
355 my($name,$email) = ($1,$2);
356 if ($package eq "") {
357 &main::DEBUG("sA: package == NULL.");
360 $maint{$name}{$email} = 1;
361 $pkg{$name}{$package} = 1;
364 &main::WARN("invalid line: '$_'.");
370 # TODO: can we use 'map' here?
371 foreach (grep /\Q$query\E/i, keys %maint) {
375 # TODO: should we only search email if '@' is used?
376 if (scalar keys %hash < 15) {
378 foreach $name (keys %maint) {
380 foreach $email (keys %{$maint{$name}}) {
381 next unless ($email =~ /\Q$query\E/i);
382 next if (exists $hash{$name});
388 my @list = keys %hash;
389 if (scalar @list != 1) {
390 my $prefix = "Debian Author Search of '$query' ";
391 &main::performStrictReply( &main::formListReply(0, $prefix, @list) );
395 &main::DEBUG("showing all packages by '$list[0]'...");
397 my @pkg = sort keys %{$pkg{$list[0]}};
399 # show how long it took.
400 my $delta_time = &main::gettimeofday() - $start_time;
401 &main::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
403 my $email = join(', ', keys %{$maint{$list[0]}});
404 my $prefix = "Debian Packages by $list[0] \002<\002$email\002>\002 ";
405 &main::performStrictReply( &main::formListReply(0, $prefix, @pkg) );
409 # Usage: &searchDesc($query);
411 my ($dist, $query) = &getDistroFromStr($_[0]);
412 &main::DEBUG("searchDesc: dist => '$dist', query => '$query'.");
413 $query =~ s/^\s+|\s+$//g;
416 my $start_time = &main::gettimeofday();
417 &main::status("Debian: starting desc search.");
420 my ($bad,$good) = (0,0);
421 my %urls = %urlpackages;
423 foreach (keys %urlpackages) {
435 &main::DEBUG("good = $good, bad = $bad...");
437 if ($good == 0 and $bad != 0) {
438 my %urls = &fixDist($dist, %urlpackages);
439 &main::DEBUG("deb: download 2c.");
440 if (!&DebianDownload($dist, %urls)) {
441 &main::ERROR("Debian(sD): could not download files.");
446 my (%desc, $package);
447 open(IN,"zegrep -h '^Package|^Description' $files |");
449 if (/^Package: (\S+)$/) {
451 } elsif (/^Description: (.*)$/) {
453 next unless ($desc =~ /\Q$query\E/i);
454 if ($package eq "") {
455 &main::WARN("sD: package == NULL?");
458 $desc{$package} = $desc;
461 &main::WARN("invalid line: '$_'.");
466 my @list = keys %desc;
468 my $prefix = "Debian Desc Search of '$query' ";
469 &main::performStrictReply( &main::formListReply(0, $prefix, ) );
470 } elsif (scalar @list == 1) { # list = 1.
471 &main::DEBUG("list == 1; showing package info of '$list[0]'.");
472 &infoPackages("info", $list[0]);
474 my $prefix = "Debian Desc Search of '$query' ";
475 &main::performStrictReply( &main::formListReply(0, $prefix, @list) );
478 # show how long it took.
479 my $delta_time = &main::gettimeofday() - $start_time;
480 &main::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
484 # Usage: &generateIncoming();
485 sub generateIncoming {
486 my $interval = $main::param{'debianRefreshInterval'};
487 my $pkgfile = "debian/Packages-incoming";
488 my $idxfile = $pkgfile.".idx";
490 $stale++ if (&main::isStale($pkgfile.".gz", $interval));
491 $stale++ if (&main::isStale($idxfile, $interval));
492 &main::DEBUG("gI: stale => '$stale'.");
493 return 0 unless ($stale);
496 my %ftp = &main::ftpList("llug.sep.bnl.gov", "/pub/debian/Incoming/");
498 if (!open(PKG,">$pkgfile")) {
499 &main::ERROR("cannot write to pkg $pkgfile.");
502 if (!open(IDX,">$idxfile")) {
503 &main::ERROR("cannot write to idx $idxfile.");
507 print IDX "*$pkgfile.gz\n";
509 foreach $file (sort keys %ftp) {
510 next unless ($file =~ /deb$/);
512 if ($file =~ /^(\S+)\_(\S+)\_(\S+)\.deb$/) {
514 print PKG "Package: $1\n";
515 print PKG "Version: $2\n";
516 print PKG "Architecture: ", (defined $4) ? $4 : "all", "\n";
518 print PKG "Filename: $file\n";
519 print PKG "Size: $ftp{$file}\n";
525 system("gzip -9fv $pkgfile"); # lame fix.
527 &main::status("Debian: generateIncoming() complete.");
531 ##############################
532 # DEBIAN PACKAGE INFO FUNCTIONS.
535 # Usage: &getPackageInfo($query,$file);
537 my ($package, $file) = @_;
540 &main::status("gPI: file $file does not exist?");
547 open(IN, "zcat $file 2>&1 |");
553 next if (/^ \S+/); # package long description.
556 if (/^Package: (.*)\n$/) {
558 if ($pkg =~ /^$package$/i) {
559 $found++; # we can use pkg{'package'} instead.
560 $pkg{'package'} = $pkg;
569 if (/^Version: (.*)$/) {
570 $pkg{'version'} = $1;
571 } elsif (/^Priority: (.*)$/) {
572 $pkg{'priority'} = $1;
573 } elsif (/^Section: (.*)$/) {
574 $pkg{'section'} = $1;
575 } elsif (/^Size: (.*)$/) {
577 } elsif (/^Installed-Size: (.*)$/i) {
578 $pkg{'installed'} = $1;
579 } elsif (/^Description: (.*)$/) {
581 } elsif (/^Filename: (.*)$/) {
583 } elsif (/^Pre-Depends: (.*)$/) {
584 $pkg{'depends'} = "pre-depends on $1";
585 } elsif (/^Depends: (.*)$/) {
586 if (exists $pkg{'depends'}) {
587 $pkg{'depends'} .= "; depends on $1";
589 $pkg{'depends'} = "depends on $1";
591 } elsif (/^Maintainer: (.*)$/) {
593 } elsif (/^Provides: (.*)$/) {
594 $pkg{'provides'} = $1;
595 } elsif (/^Suggests: (.*)$/) {
596 $pkg{'suggests'} = $1;
597 } elsif (/^Conflicts: (.*)$/) {
598 $pkg{'conflicts'} = $1;
601 ### &main::DEBUG("=> '$_'.");
611 next if (defined $pkg);
619 # Usage: &infoPackages($query,$package);
621 my ($query,$dist,$package) = ($_[0], &getDistroFromStr($_[1]));
622 my $interval = $main::param{'debianRefreshInterval'} || 7;
624 &main::status("Debian: Searching for package '$package' in '$dist'.");
626 # download packages file.
628 my %urls = &fixDist($dist, %urlpackages);
629 if ($dist ne "incoming") {
630 &main::DEBUG("deb: download 3.");
631 if (!&DebianDownload($dist, %urls)) { # no good download.
632 &main::WARN("Debian(iP): could not download ANY files.");
636 # check if the package is valid.
638 my @files = &validPackage($package, $dist);
639 if (!scalar @files) {
640 &main::status("Debian: no valid package found; checking incoming.");
641 @files = &validPackage($package, "incoming");
643 &main::status("Debian: cool, it exists in incoming.");
646 &main::msg($main::who, "Package '$package' does not exist.");
651 if (scalar @files > 1) {
652 &main::WARN("same package in more than one file; random.");
653 &main::DEBUG("THIS SHOULD BE FIXED SOMEHOW!!!");
654 $files[0] = &main::getRandom(@files);
657 if (! -f $files[0]) {
658 &main::WARN("files[0] ($files[0]) doesn't exist.");
659 &main::msg($main::who, "WARNING: $files[0] does not exist? FIXME");
663 ### TODO: if specific package is requested, note down that a version
664 ### exists in incoming.
667 my $file = $files[0];
670 ### TODO: use fe, dump to a hash. if only one version of the package
671 ### exists. do as normal otherwise list all versions.
673 &main::ERROR("D:iP: file '$file' DOES NOT EXIST!!! should never happen.");
676 my %pkg = &getPackageInfo($package, $file);
679 if ($query eq "info") {
680 if (scalar keys %pkg > 5) {
681 $pkg{'info'} = "\002(\002". $pkg{'desc'} ."\002)\002";
682 $pkg{'info'} .= ", section ".$pkg{'section'};
683 $pkg{'info'} .= ", is ".$pkg{'priority'};
684 $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
685 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
686 $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
689 &main::status("iP: info requested and pkg is in incoming, too.");
690 my %incpkg = &getPackageInfo($query, "debian/Packages-incoming");
692 if (scalar keys %incpkg) {
693 $pkg{'info'} .= ". Is in incoming ($incpkg{'file'}).";
695 &main::ERROR("iP: pkg $query is in incoming but we couldn't get any info?");
699 &main::DEBUG("running debianCheck() due to problems (".scalar(keys %pkg).").");
701 &main::DEBUG("end of debianCheck()");
703 &main::msg($main::who,"Debian: Package appears to exist but I could not retrieve info about it...");
708 if ($dist eq "incoming") {
709 $pkg{'info'} .= "Version: \002$pkg{'version'}\002";
710 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
711 $pkg{'info'} .= ", is in incoming!!!";
714 if (!exists $pkg{$query}) {
715 if ($query eq "suggests") {
716 $pkg{$query} = "has no suggestions";
717 } elsif ($query eq "conflicts") {
718 $pkg{$query} = "does not conflict with any other package";
719 } elsif ($query eq "depends") {
720 $pkg{$query} = "does not depend on anything";
721 } elsif ($query eq "maint") {
722 $pkg{$query} = "has no maintainer";
724 $pkg{$query} = "has nothing about $query";
728 &main::performStrictReply("$package: $pkg{$query}");
731 # Usage: &infoStats($dist);
734 $dist = &getDistro($dist);
735 return unless (defined $dist);
737 &main::DEBUG("infoS: dist => '$dist'.");
738 my $interval = $main::param{'debianRefreshInterval'} || 7;
740 # download packages file if needed.
741 my %urls = &fixDist($dist, %urlpackages);
742 &main::DEBUG("deb: download 4.");
743 if (!&DebianDownload($dist, %urls)) {
744 &main::WARN("Debian(iS): could not download ANY files.");
745 &main::msg($main::who, "Debian(iS): internal error.");
752 foreach $file (keys %urlpackages) {
753 $file =~ s/##DIST/$dist/g; # won't work for incoming.
754 &main::DEBUG("file => '$file'.");
755 if (exists $stats{$file}{'count'}) {
756 &main::DEBUG("hrm... duplicate open with $file???");
760 open(IN,"zcat $file 2>&1 |");
763 &main::DEBUG("iS: $file does not exist.");
770 next if (/^ \S+/); # package long description.
772 if (/^Package: (.*)\n$/) { # counter.
773 $stats{$file}{'count'}++;
775 } elsif (/^Maintainer: .* <(\S+)>$/) {
776 $stats{$file}{'maint'}{$1}++;
777 $total{'maint'}{$1}++;
778 } elsif (/^Size: (.*)$/) { # compressed size.
779 $stats{$file}{'csize'} += $1;
780 $total{'csize'} += $1;
781 } elsif (/^i.*size: (.*)$/i) { # installed size.
782 $stats{$file}{'isize'} += $1;
783 $total{'isize'} += $1;
786 ### &main::DEBUG("=> '$_'.");
791 &main::performStrictReply(
792 "Debian Distro Stats on $dist... ".
793 "\002$total{'count'}\002 packages, ".
794 "\002".scalar(keys %{$total{'maint'}})."\002 maintainers, ".
795 "\002". int($total{'isize'}/1024)."\002 MB installed size, ".
796 "\002". int($total{'csize'}/1024/1024)."\002 MB compressed size."
799 ### TODO: do individual stats? if so, we need _another_ arg.
800 # foreach $file (keys %stats) {
801 # foreach (keys %{$stats{$file}}) {
802 # &main::DEBUG(" '$file' '$_' '$stats{$file}{$_}'.");
812 # HELPER FUNCTIONS FOR INFOPACKAGES...
815 # Usage: &generateIndex();
818 &main::status("Debian: !!! generateIndex() called !!!");
819 if (!scalar @dists or $dists[0] eq '') {
820 &main::ERROR("gI: no dists to generate index.");
825 my $dist = &getDistro($_); # incase the alias is returned, possible?
826 my $idx = "debian/Packages-$dist.idx";
828 # TODO: check if any of the Packages file have been updated then
829 # regenerate it, even if it's not stale.
830 # TODO: also, regenerate the index if the packages file is newer
832 next unless (&main::isStale($idx, $main::param{'debianRefreshInterval'}));
834 &main::DEBUG("gIndex: calling generateIncoming()!");
839 &main::DEBUG("gIndeX: calling DebianDownload($dist, ...).");
840 &DebianDownload($dist, %urlpackages);
842 &main::status("Debian: generating index for '$dist'.");
843 if (!open(OUT,">$idx")) {
844 &main::ERROR("cannot write to $idx.");
849 foreach $packages (keys %urlpackages) {
850 $packages =~ s/##DIST/$dist/;
852 if (! -e $packages) {
853 &main::ERROR("gIndex: '$packages' does not exist?");
857 print OUT "*$packages\n";
858 open(IN,"zcat $packages |");
861 next unless (/^Package: (.*)\n$/);
872 # Usage: &validPackage($package, $dist);
874 my ($package,$dist) = @_;
878 &main::DEBUG("D: validPackage($package, $dist) called.");
881 while (!open(IN, "debian/Packages-$dist.idx")) {
883 &main::ERROR("Packages-$dist.idx does not exist (#1).");
887 &generateIndex($dist);
899 if (/^$package\n$/) {
906 &main::DEBUG("vP: scanned $count items in index.");
912 my ($dist, $query) = &getDistroFromStr($_[0]);
913 my $file = "debian/Packages-$dist.idx";
917 &main::status("Debian: Search package matching '$query' in '$dist'.");
918 unlink $file if ( -z $file);
920 while (!open(IN, $file)) {
921 if ($dist eq "incoming") {
922 &main::DEBUG("sP: dist == incoming; calling gI().");
927 &main::ERROR("could not generate index!!!");
932 &main::DEBUG("should we be doing this?");
933 &generateIndex(($dist));
942 if (&main::isStale($file, $main::param{'debianRefreshInterval'})) {
943 &main::DEBUG("STALE $file! regen.");
944 &generateIndex(($dist));
945 ### @files = searchPackage("$query $dist");
946 &main::DEBUG("EVIL HACK HACK HACK.");
965 if (!defined $dist or $dist eq "") {
966 &main::DEBUG("gD: dist == NULL; dist = defaultdist.");
967 $dist = $defaultdist;
970 if ($dist =~ /^(slink|hamm|rex|bo)$/i) {
971 &main::DEBUG("Debian: deprecated version ($dist).");
972 &main::msg($main::who, "Debian: deprecated distribution version.");
976 if (exists $dists{$dist}) {
977 return $dists{$dist};
979 if (!grep /^\Q$dist\E$/i, %dists) {
980 &main::msg($main::who, "invalid dist '$dist'.");
988 sub getDistroFromStr {
990 my $dists = join '|', %dists;
991 my $dist = $defaultdist;
993 if ($str =~ s/\s+($dists)$//i) {
994 $dist = &getDistro(lc $1);
997 $str =~ s/\\([\$\^])/$1/g;
1003 my ($dist, %urls) = @_;
1007 while (($key,$val) = each %urls) {
1008 $key =~ s/##DIST/$dist/;
1009 $val =~ s/##DIST/$dist/;
1010 ### TODO: what should we do if the sar wasn't done.
1017 ### H-H-H-HACK HACK HACK :)
1019 my ($dist, $query) = &getDistroFromStr($str);
1020 my @results = sort &searchPackage($str);
1022 if (!scalar @results) {
1023 &main::Forker("debian", sub { &searchContents($str); } );
1024 } elsif (scalar @results == 1) {
1025 &main::status("searchPackage returned one result; getting info of package instead!");
1026 &main::Forker("debian", sub { &infoPackages("info", "$results[0] $dist"); } );
1028 my $prefix = "Debian Package Listing of '$str' ";
1029 &main::performStrictReply( &main::formListReply(0, $prefix, @results) );
1034 my $dir = "debian/";
1037 &main::status("debianCheck() called.");
1039 ### TODO: remove the following loop (check if dir exists before)
1041 last if (opendir(DEBIAN, $dir));
1043 &main::ERROR("dC: cannot opendir debian.");
1052 while (defined($file = readdir DEBIAN)) {
1053 next unless ($file =~ /(gz|bz2)$/);
1055 my $exit = system("gzip -t '$dir/$file'");
1056 next unless ($exit);
1057 &main::DEBUG("hmr... => ".(time() - (stat($file))[8])."'.");
1058 next unless (time() - (stat($file))[8] > 3600);
1060 &main::DEBUG("dC: exit => '$exit'.");
1061 &main::WARN("dC: '$dir/$file' corrupted? deleting!");
1062 unlink $dir."/".$file;