2 # Debian.pl: Frontend to debian contents and packages files
4 # Version: v0.8 (20000918)
12 # format: "alias=real".
14 my $defaultdist = "unstable";
15 my $refresh = &::getChanConfDefault("debianRefreshInterval",
16 undef, 7) * 60 * 60 * 24;
20 "testing" => "woody", # new since 20001219.
22 "incoming" => "incoming",
23 ### the following don't work. too much effort to get 3 types of distros
24 ### to work harmoniously :-)
25 "slink" => "archive-2.1",
26 "hamm" => "archive-2.0",
27 "rex" => "archive-1.?",
28 "bo" => "archive-1.?",
32 "debian/Contents-##DIST-i386.gz" =>
33 "ftp://ftp.us.debian.org".
34 "/debian/dists/##DIST/Contents-i386.gz",
35 ### APPEARS TO BE FIXED?
36 # => strip control chars just to be safe.
37 "debian/Contents-##DIST-i386-non-US.gz" =>
38 "ftp://non-us.debian.org".
39 "/debian-non-US/dists/##DIST/non-US/Contents-i386.gz",
43 "debian/Packages-##DIST-main-i386.gz" =>
44 "ftp://ftp.us.debian.org".
45 "/debian/dists/##DIST/main/binary-i386/Packages.gz",
46 "debian/Packages-##DIST-contrib-i386.gz" =>
47 "ftp://ftp.us.debian.org".
48 "/debian/dists/##DIST/contrib/binary-i386/Packages.gz",
49 "debian/Packages-##DIST-non-free-i386.gz" =>
50 "ftp://ftp.us.debian.org".
51 "/debian/dists/##DIST/non-free/binary-i386/Packages.gz",
53 "debian/Packages-##DIST-non-US-main-i386.gz" =>
54 "ftp://non-us.debian.org".
55 "/debian-non-US/dists/##DIST/non-US/main/binary-i386/Packages.gz",
56 "debian/Packages-##DIST-non-US-contrib-i386.gz" =>
57 "ftp://non-us.debian.org".
58 "/debian-non-US/dists/##DIST/non-US/contrib/binary-i386/Packages.gz",
59 "debian/Packages-##DIST-non-US-non-free-i386.gz" =>
60 "ftp://non-us.debian.org".
61 "/debian-non-US/dists/##DIST/non-US/non-free/binary-i386/Packages.gz",
65 ### COMMON FUNCTION....
66 #######################
69 # Usage: &DebianDownload(%hash);
71 my ($dist, %urls) = @_;
76 &::status("Debian: creating debian dir.");
77 mkdir("debian/",0755);
84 foreach $file (keys %urls) {
85 my $url = $urls{$file};
86 $url =~ s/##DIST/$dist/g;
87 $file =~ s/##DIST/$dist/g;
91 my $last_refresh = (stat($file))[9];
92 $update++ if (time() - $last_refresh > $refresh);
97 next unless ($update);
99 &::DEBUG("announce == $announce.");
100 if ($good + $bad == 0 and !$announce) {
101 &::status("Debian: Downloading files for '$dist'.");
102 &::msg($::who, "Updating debian files... please wait.");
106 if (exists $::debian{$url}) {
107 &::DEBUG("2: ".(time - $::debian{$url})." <= $refresh");
108 next if (time() - $::debian{$url} <= $refresh);
109 &::DEBUG("stale for url $url; updating!");
112 if ($url =~ /^ftp:\/\/(.*?)\/(\S+)\/(\S+)$/) {
113 my ($host,$path,$thisfile) = ($1,$2,$3);
115 # error internally to ftp.
116 # hope it doesn't do anything bad.
117 if ($file =~ /Contents-woody-i386-non-US/) {
118 &::DEBUG("Skipping Contents-woody-i386-non-US.");
119 # $file =~ s/woody/potato/;
120 # $path =~ s/woody/potato/;
124 if (!&::ftpGet($host,$path,$thisfile,$file)) {
125 &::WARN("deb: down: $file == BAD.");
131 &::DEBUG("deb: down: ftpGet: !file");
136 if ($file =~ /Contents-potato-i386-non-US/) {
137 &::DEBUG("hack: using potato's non-US contents for woody.");
138 system("cp debian/Contents-potato-i386-non-US.gz debian/Contents-woody-i386-non-US.gz");
141 &::DEBUG("deb: download: good.");
145 &::ERROR("Debian: invalid format of url => ($url).");
152 &generateIndex($dist);
155 return -1 unless ($bad); # no download.
156 &::DEBUG("DD: !good and bad($bad). :(");
161 ###########################
162 # DEBIAN CONTENTS SEARCH FUNCTIONS.
166 # Usage: &searchContents($query);
168 my ($dist, $query) = &getDistroFromStr($_[0]);
169 &::status("Debian: Contents search for '$query' on $dist.");
172 $dccsend++ if ($query =~ s/^dcc\s+//i);
174 # $query = $query.'(\.so\.)?([.[[:digit:]]+\.]+)?$';
176 $query =~ s/\\([\^\$])/$1/g; # hrm?
177 $query =~ s/^\s+|\s+$//g;
179 if (!&::validExec($query)) {
180 &::msg($::who, "search string looks fuzzy.");
184 if ($dist eq "incoming") { # nothing yet.
185 &::DEBUG("sC: dist = 'incoming'. no contents yet.");
188 my %urls = &fixDist($dist, %urlcontents);
189 # download contents file.
190 &::DEBUG("deb: download 1.");
191 if (!&DebianDownload($dist, %urls)) {
192 &::WARN("Debian: could not download files.");
197 my $start_time = &::timeget();
203 ### TODO: search properly if /usr/bin/blah is done.
204 if ($query =~ s/\$$//) {
205 &::DEBUG("search-regex found.");
206 $grepRE = "$query\[ \t]";
207 } elsif ($query =~ s/^\^//) {
208 &::DEBUG("front marker regex found.");
212 $grepRE = "$query*\[ \t]";
215 ### fix up grepRE for "*".
216 $grepRE =~ s/\*/.*/g;
219 foreach (keys %urlcontents) {
222 next unless ( -f $_);
226 if (!scalar @files) {
227 &::ERROR("sC: no files?");
228 &::msg($::who, "failed.");
232 my $files = join(' ', @files);
234 open(IN,"zegrep -h '$grepRE' $files |");
236 if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) {
237 my ($file,$package) = ("/".$1,$2);
238 if ($query =~ /\//) {
239 next unless ($file =~ /\Q$query\E/);
241 my ($basename) = $file =~ /^.*\/(.*)$/;
242 next unless ($basename =~ /\Q$query\E/);
244 next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//);
245 next if ($front and $file !~ /^\/\Q$query\E/);
247 $contents{$package}{$file} = 1;
251 last if ($found > 100);
257 ### send results with dcc.
259 if (exists $::dcc{'SEND'}{$::who}) {
260 &::msg($::who, "DCC already active!");
264 if (!scalar %contents) {
265 &::msg($::who,"search returned no results.");
269 my $file = "$::param{tempDir}/$::who.txt";
270 if (!open(OUT,">$file")) {
271 &::ERROR("Debian: cannot write file for dcc send.");
275 foreach $pkg (keys %contents) {
276 foreach (keys %{$contents{$pkg}}) {
277 # TODO: correct padding.
278 print OUT "$_\t\t\t$pkg\n";
283 &::shmWrite($::shm, "DCC SEND $::who $file");
288 &::status("Debian: $found contents results found.");
291 foreach $pkg (keys %contents) {
292 my @tmplist = &::fixFileList(keys %{$contents{$pkg}});
293 my @sublist = sort { length $a <=> length $b } @tmplist;
295 pop @sublist while (scalar @sublist > 3);
297 $pkg =~ s/\,/\037\,\037/g; # underline ','.
298 push(@list, "(". join(', ',@sublist) .") in $pkg");
300 # sort the total list from shortest to longest...
301 @list = sort { length $a <=> length $b } @list;
303 # show how long it took.
304 my $delta_time = &::timedelta($start_time);
305 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
307 my $prefix = "Debian Search of '$query' ";
308 if (scalar @list) { # @list.
309 &::pSReply( &::formListReply(0, $prefix, @list) );
311 &::DEBUG("ok, !\@list, searching desc for '$query'.");
317 # Usage: &searchAuthor($query);
319 my ($dist, $query) = &getDistroFromStr($_[0]);
320 &::DEBUG("searchAuthor: dist => '$dist', query => '$query'.");
321 $query =~ s/^\s+|\s+$//g;
324 my $start_time = &::timeget();
325 &::status("Debian: starting author search.");
328 my ($bad,$good) = (0,0);
329 my %urls = %urlpackages;
331 foreach (keys %urlpackages) {
343 &::DEBUG("good = $good, bad = $bad...");
345 if ($good == 0 and $bad != 0) {
346 my %urls = &fixDist($dist, %urlpackages);
347 &::DEBUG("deb: download 2.");
348 if (!&DebianDownload($dist, %urls)) {
349 &::ERROR("Debian(sA): could not download files.");
354 my (%maint, %pkg, $package);
355 open(IN,"zegrep -h '^Package|^Maintainer' $files |");
357 if (/^Package: (\S+)$/) {
359 } elsif (/^Maintainer: (.*) \<(\S+)\>$/) {
360 my($name,$email) = ($1,$2);
361 if ($package eq "") {
362 &::DEBUG("sA: package == NULL.");
365 $maint{$name}{$email} = 1;
366 $pkg{$name}{$package} = 1;
369 &::WARN("invalid line: '$_'.");
375 # TODO: can we use 'map' here?
376 foreach (grep /\Q$query\E/i, keys %maint) {
380 # TODO: should we only search email if '@' is used?
381 if (scalar keys %hash < 15) {
383 foreach $name (keys %maint) {
385 foreach $email (keys %{$maint{$name}}) {
386 next unless ($email =~ /\Q$query\E/i);
387 next if (exists $hash{$name});
393 my @list = keys %hash;
394 if (scalar @list != 1) {
395 my $prefix = "Debian Author Search of '$query' ";
396 &::pSReply( &::formListReply(0, $prefix, @list) );
400 &::DEBUG("showing all packages by '$list[0]'...");
402 my @pkg = sort keys %{$pkg{$list[0]}};
404 # show how long it took.
405 my $delta_time = &::timedelta($start_time);
406 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
408 my $email = join(', ', keys %{$maint{$list[0]}});
409 my $prefix = "Debian Packages by $list[0] \002<\002$email\002>\002 ";
410 &::pSReply( &::formListReply(0, $prefix, @pkg) );
414 # Usage: &searchDesc($query);
416 my ($dist, $query) = &getDistroFromStr($_[0]);
417 &::DEBUG("searchDesc: dist => '$dist', query => '$query'.");
418 $query =~ s/^\s+|\s+$//g;
421 my $start_time = &::timeget();
422 &::status("Debian: starting desc search.");
425 my ($bad,$good) = (0,0);
426 my %urls = %urlpackages;
428 foreach (keys %urlpackages) {
440 &::DEBUG("good = $good, bad = $bad...");
442 if ($good == 0 and $bad != 0) {
443 my %urls = &fixDist($dist, %urlpackages);
444 &::DEBUG("deb: download 2c.");
445 if (!&DebianDownload($dist, %urls)) {
446 &::ERROR("Debian(sD): could not download files.");
451 my (%desc, $package);
452 open(IN,"zegrep -h '^Package|^Description' $files |");
453 $query =~ s/\*/\\S*/g; # regex.
455 if (/^Package: (\S+)$/) {
457 } elsif (/^Description: (.*)$/) {
459 next unless ($desc =~ /\Q$query\E/i);
460 if ($package eq "") {
461 &::WARN("sD: package == NULL?");
464 $desc{$package} = $desc;
467 &::WARN("invalid line: '$_'.");
472 my @list = keys %desc;
474 my $prefix = "Debian Desc Search of '$query' ";
475 &::pSReply( &::formListReply(0, $prefix, ) );
476 } elsif (scalar @list == 1) { # list = 1.
477 &::DEBUG("list == 1; showing package info of '$list[0]'.");
478 &infoPackages("info", $list[0]);
480 my $prefix = "Debian Desc Search of '$query' ";
481 &::pSReply( &::formListReply(0, $prefix, @list) );
484 # show how long it took.
485 my $delta_time = &::timedelta($start_time);
486 &::status(sprintf("Debian: %.02f sec to complete query.", $delta_time)) if ($delta_time > 0);
490 # Usage: &generateIncoming();
491 sub generateIncoming {
492 my $pkgfile = "debian/Packages-incoming";
493 my $idxfile = $pkgfile.".idx";
495 $stale++ if (&::isStale($pkgfile.".gz", $refresh));
496 $stale++ if (&::isStale($idxfile, $refresh));
497 &::DEBUG("gI: stale => '$stale'.");
498 return 0 unless ($stale);
501 my %ftp = &::ftpList("llug.sep.bnl.gov", "/pub/debian/Incoming/");
503 if (!open(PKG,">$pkgfile")) {
504 &::ERROR("cannot write to pkg $pkgfile.");
507 if (!open(IDX,">$idxfile")) {
508 &::ERROR("cannot write to idx $idxfile.");
512 print IDX "*$pkgfile.gz\n";
514 foreach $file (sort keys %ftp) {
515 next unless ($file =~ /deb$/);
517 if ($file =~ /^(\S+)\_(\S+)\_(\S+)\.deb$/) {
519 print PKG "Package: $1\n";
520 print PKG "Version: $2\n";
521 print PKG "Architecture: ", (defined $4) ? $4 : "all", "\n";
523 print PKG "Filename: $file\n";
524 print PKG "Size: $ftp{$file}\n";
530 system("gzip -9fv $pkgfile"); # lame fix.
532 &::status("Debian: generateIncoming() complete.");
536 ##############################
537 # DEBIAN PACKAGE INFO FUNCTIONS.
540 # Usage: &getPackageInfo($query,$file);
542 my ($package, $file) = @_;
545 &::status("gPI: file $file does not exist?");
552 open(IN, "zcat $file 2>&1 |");
558 next if (/^ \S+/); # package long description.
561 if (/^Package: (.*)\n$/) {
563 if ($pkg =~ /^$package$/i) {
564 $found++; # we can use pkg{'package'} instead.
565 $pkg{'package'} = $pkg;
574 if (/^Version: (.*)$/) {
575 $pkg{'version'} = $1;
576 } elsif (/^Priority: (.*)$/) {
577 $pkg{'priority'} = $1;
578 } elsif (/^Section: (.*)$/) {
579 $pkg{'section'} = $1;
580 } elsif (/^Size: (.*)$/) {
582 } elsif (/^Installed-Size: (.*)$/i) {
583 $pkg{'installed'} = $1;
584 } elsif (/^Description: (.*)$/) {
586 } elsif (/^Filename: (.*)$/) {
588 } elsif (/^Pre-Depends: (.*)$/) {
589 $pkg{'depends'} = "pre-depends on $1";
590 } elsif (/^Depends: (.*)$/) {
591 if (exists $pkg{'depends'}) {
592 $pkg{'depends'} .= "; depends on $1";
594 $pkg{'depends'} = "depends on $1";
596 } elsif (/^Maintainer: (.*)$/) {
598 } elsif (/^Provides: (.*)$/) {
599 $pkg{'provides'} = $1;
600 } elsif (/^Suggests: (.*)$/) {
601 $pkg{'suggests'} = $1;
602 } elsif (/^Conflicts: (.*)$/) {
603 $pkg{'conflicts'} = $1;
606 ### &::DEBUG("=> '$_'.");
616 next if (defined $pkg);
624 # Usage: &infoPackages($query,$package);
626 my ($query,$dist,$package) = ($_[0], &getDistroFromStr($_[1]));
628 &::status("Debian: Searching for package '$package' in '$dist'.");
630 # download packages file.
632 my %urls = &fixDist($dist, %urlpackages);
633 if ($dist ne "incoming") {
634 &::DEBUG("deb: download 3.");
635 if (!&DebianDownload($dist, %urls)) { # no good download.
636 &::WARN("Debian(iP): could not download ANY files.");
640 # check if the package is valid.
642 my @files = &validPackage($package, $dist);
643 if (!scalar @files) {
644 &::status("Debian: no valid package found; checking incoming.");
645 @files = &validPackage($package, "incoming");
647 &::status("Debian: cool, it exists in incoming.");
650 &::msg($::who, "Package '$package' does not exist.");
655 if (scalar @files > 1) {
656 &::WARN("same package in more than one file; random.");
657 &::DEBUG("THIS SHOULD BE FIXED SOMEHOW!!!");
658 $files[0] = &::getRandom(@files);
661 if (! -f $files[0]) {
662 &::WARN("files[0] ($files[0]) doesn't exist.");
663 &::msg($::who, "WARNING: $files[0] does not exist? FIXME");
667 ### TODO: if specific package is requested, note down that a version
668 ### exists in incoming.
671 my $file = $files[0];
674 ### TODO: use fe, dump to a hash. if only one version of the package
675 ### exists. do as normal otherwise list all versions.
677 &::ERROR("D:iP: file '$file' DOES NOT EXIST!!! should never happen.");
680 my %pkg = &getPackageInfo($package, $file);
683 if ($query eq "info") {
684 if (scalar keys %pkg > 5) {
685 $pkg{'info'} = "\002(\002". $pkg{'desc'} ."\002)\002";
686 $pkg{'info'} .= ", section ".$pkg{'section'};
687 $pkg{'info'} .= ", is ".$pkg{'priority'};
688 $pkg{'info'} .= ". Version: \002$pkg{'version'}\002";
689 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
690 $pkg{'info'} .= ", Installed size: \002$pkg{'installed'}\002 kB";
693 &::status("iP: info requested and pkg is in incoming, too.");
694 my %incpkg = &getPackageInfo($query, "debian/Packages-incoming");
696 if (scalar keys %incpkg) {
697 $pkg{'info'} .= ". Is in incoming ($incpkg{'file'}).";
699 &::ERROR("iP: pkg $query is in incoming but we couldn't get any info?");
703 &::DEBUG("running debianCheck() due to problems (".scalar(keys %pkg).").");
705 &::DEBUG("end of debianCheck()");
707 &::msg($::who,"Debian: Package appears to exist but I could not retrieve info about it...");
712 if ($dist eq "incoming") {
713 $pkg{'info'} .= "Version: \002$pkg{'version'}\002";
714 $pkg{'info'} .= ", Packaged size: \002". int($pkg{'size'}/1024) ."\002 kB";
715 $pkg{'info'} .= ", is in incoming!!!";
718 if (!exists $pkg{$query}) {
719 if ($query eq "suggests") {
720 $pkg{$query} = "has no suggestions";
721 } elsif ($query eq "conflicts") {
722 $pkg{$query} = "does not conflict with any other package";
723 } elsif ($query eq "depends") {
724 $pkg{$query} = "does not depend on anything";
725 } elsif ($query eq "maint") {
726 $pkg{$query} = "has no maintainer";
728 $pkg{$query} = "has nothing about $query";
732 &::pSReply("$package: $pkg{$query}");
735 # Usage: &infoStats($dist);
738 $dist = &getDistro($dist);
739 return unless (defined $dist);
741 &::DEBUG("infoS: dist => '$dist'.");
743 # download packages file if needed.
744 my %urls = &fixDist($dist, %urlpackages);
745 &::DEBUG("deb: download 4.");
746 if (!&DebianDownload($dist, %urls)) {
747 &::WARN("Debian(iS): could not download ANY files.");
748 &::msg($::who, "Debian(iS): internal error.");
755 foreach $file (keys %urlpackages) {
756 $file =~ s/##DIST/$dist/g; # won't work for incoming.
757 &::DEBUG("file => '$file'.");
758 if (exists $stats{$file}{'count'}) {
759 &::DEBUG("hrm... duplicate open with $file???");
763 open(IN,"zcat $file 2>&1 |");
766 &::DEBUG("iS: $file does not exist.");
773 next if (/^ \S+/); # package long description.
775 if (/^Package: (.*)\n$/) { # counter.
776 $stats{$file}{'count'}++;
778 } elsif (/^Maintainer: .* <(\S+)>$/) {
779 $stats{$file}{'maint'}{$1}++;
780 $total{'maint'}{$1}++;
781 } elsif (/^Size: (.*)$/) { # compressed size.
782 $stats{$file}{'csize'} += $1;
783 $total{'csize'} += $1;
784 } elsif (/^i.*size: (.*)$/i) { # installed size.
785 $stats{$file}{'isize'} += $1;
786 $total{'isize'} += $1;
789 ### &::DEBUG("=> '$_'.");
794 ### TODO: don't count ppl with multiple email addresses.
797 "Debian Distro Stats on $dist... ".
798 "\002$total{'count'}\002 packages, ".
799 "\002".scalar(keys %{$total{'maint'}})."\002 maintainers, ".
800 "\002". int($total{'isize'}/1024)."\002 MB installed size, ".
801 "\002". int($total{'csize'}/1024/1024)."\002 MB compressed size."
804 ### TODO: do individual stats? if so, we need _another_ arg.
805 # foreach $file (keys %stats) {
806 # foreach (keys %{$stats{$file}}) {
807 # &::DEBUG(" '$file' '$_' '$stats{$file}{$_}'.");
817 # HELPER FUNCTIONS FOR INFOPACKAGES...
820 # Usage: &generateIndex();
823 &::status("Debian: !!! generateIndex() called !!!");
824 if (!scalar @dists or $dists[0] eq '') {
825 &::ERROR("gI: no dists to generate index.");
830 my $dist = &getDistro($_); # incase the alias is returned, possible?
831 my $idx = "debian/Packages-$dist.idx";
833 # TODO: check if any of the Packages file have been updated then
834 # regenerate it, even if it's not stale.
835 # TODO: also, regenerate the index if the packages file is newer
837 next unless (&::isStale($idx, $::param{'debianRefreshInterval'}));
839 &::DEBUG("gIndex: calling generateIncoming()!");
845 &::DEBUG("Copying old index of woody to -old");
846 system("cp $idx $idx-old");
849 &::DEBUG("gIndeX: calling DebianDownload($dist, ...).");
850 &DebianDownload($dist, %urlpackages);
852 &::status("Debian: generating index for '$dist'.");
853 if (!open(OUT,">$idx")) {
854 &::ERROR("cannot write to $idx.");
859 foreach $packages (keys %urlpackages) {
860 $packages =~ s/##DIST/$dist/;
862 if (! -e $packages) {
863 &::ERROR("gIndex: '$packages' does not exist?");
867 print OUT "*$packages\n";
868 open(IN,"zcat $packages |");
871 next unless (/^Package: (.*)\n$/);
882 # Usage: &validPackage($package, $dist);
884 my ($package,$dist) = @_;
888 &::DEBUG("D: validPackage($package, $dist) called.");
891 while (!open(IN, "debian/Packages-$dist.idx")) {
893 &::ERROR("Packages-$dist.idx does not exist (#1).");
897 &generateIndex($dist);
909 if (/^\Q$package\E\n$/) {
916 &::DEBUG("vP: scanned $count items in index.");
922 my ($dist, $query) = &getDistroFromStr($_[0]);
923 my $file = "debian/Packages-$dist.idx";
928 if ($query =~ tr/A-Z/a-z/) {
932 &::status("Debian: Search package matching '$query' in '$dist'.");
933 unlink $file if ( -z $file);
935 while (!open(IN, $file)) {
936 if ($dist eq "incoming") {
937 &::DEBUG("sP: dist == incoming; calling gI().");
942 &::ERROR("could not generate index!!!");
947 &::DEBUG("should we be doing this?");
948 &generateIndex(($dist));
957 if (&::isStale($file, $::param{'debianRefreshInterval'})) {
958 &::DEBUG("STALE $file! regen.");
959 &generateIndex(($dist));
960 ### @files = searchPackage("$query $dist");
961 &::DEBUG("EVIL HACK HACK HACK.");
974 if (scalar @files and $warn) {
975 &::msg($::who, "searching for package name should be fully lowercase!");
984 if (!defined $dist or $dist eq "") {
985 &::DEBUG("gD: dist == NULL; dist = defaultdist.");
986 $dist = $defaultdist;
989 if ($dist =~ /^(slink|hamm|rex|bo)$/i) {
990 &::DEBUG("Debian: deprecated version ($dist).");
991 &::msg($::who, "Debian: deprecated distribution version.");
995 if (exists $dists{$dist}) {
996 return $dists{$dist};
998 if (!grep /^\Q$dist\E$/i, %dists) {
999 &::msg($::who, "invalid dist '$dist'.");
1007 sub getDistroFromStr {
1009 my $dists = join '|', %dists;
1010 my $dist = $defaultdist;
1012 if ($str =~ s/\s+($dists)$//i) {
1013 $dist = &getDistro(lc $1);
1016 $str =~ s/\\([\$\^])/$1/g;
1022 my ($dist, %urls) = @_;
1026 while (($key,$val) = each %urls) {
1027 $key =~ s/##DIST/$dist/;
1028 $val =~ s/##DIST/$dist/;
1029 ### TODO: what should we do if the sar wasn't done.
1036 ### H-H-H-HACK HACK HACK :)
1038 my ($dist, $query) = &getDistroFromStr($str);
1039 my @results = sort &searchPackage($str);
1041 if (!scalar @results) {
1042 &::Forker("debian", sub { &searchContents($str); } );
1043 } elsif (scalar @results == 1) {
1044 &::status("searchPackage returned one result; getting info of package instead!");
1045 &::Forker("debian", sub { &infoPackages("info", "$results[0] $dist"); } );
1047 my $prefix = "Debian Package Listing of '$str' ";
1048 &::pSReply( &::formListReply(0, $prefix, @results) );
1053 my $dir = "debian/";
1056 &::status("debianCheck() called.");
1058 ### TODO: remove the following loop (check if dir exists before)
1060 last if (opendir(DEBIAN, $dir));
1062 &::ERROR("dC: cannot opendir debian.");
1071 while (defined($file = readdir DEBIAN)) {
1072 next unless ($file =~ /(gz|bz2)$/);
1074 my $exit = system("gzip -t '$dir/$file'");
1075 next unless ($exit);
1076 &::DEBUG("hmr... => ".(time() - (stat($file))[8])."'.");
1077 next unless (time() - (stat($file))[8] > 3600);
1079 &::DEBUG("dC: exit => '$exit'.");
1080 &::WARN("dC: '$dir/$file' corrupted? deleting!");
1081 unlink $dir."/".$file;