X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FDebian.pl;h=7ff7708c7c5b2fcf5f2296c070ef27f8e7be2282;hb=130fc9d79663d571b32c8a625e3487e7b42c10da;hp=eb7f2e0c217549d6bb23d28847cae60c14709b3d;hpb=626da38d992b33bb84f6f697d13fff7215976f10;p=infobot.git diff --git a/src/Modules/Debian.pl b/src/Modules/Debian.pl index eb7f2e0..7ff7708 100644 --- a/src/Modules/Debian.pl +++ b/src/Modules/Debian.pl @@ -69,7 +69,7 @@ my %urlpackages = ( ####################### #### -# Usage: &DebianDownload(%hash); +# Usage: &DebianDownload($dist, %hash); sub DebianDownload { my ($dist, %urls) = @_; my $bad = 0; @@ -89,7 +89,7 @@ sub DebianDownload { $file =~ s/##DIST/$dist/g; my $update = 0; - if ( -f $file) { + if ( -f $file ) { my $last_refresh = (stat $file)[9]; $update++ if (time() - $last_refresh > $refresh); } else { @@ -149,6 +149,9 @@ sub DebianDownload { } } + # ok... lets just run this. + &::miscCheck(); + if ($good) { &generateIndex($dist); return 1; @@ -218,8 +221,8 @@ sub searchContents { foreach (keys %urlcontents) { s/##DIST/$dist/g; - next unless ( -f $_); - push(@files,$_); + next unless ( -f "$debian_dir/$_" ); + push(@files, "$debian_dir/$_"); } if (!scalar @files) { @@ -236,26 +239,27 @@ sub searchContents { $regex =~ s/\?/./g; open(IN,"zegrep -h '$grepRE' $files |"); + # wonderful abuse of last and next and unless ;) while () { - if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/) { - my ($file,$package) = ("/".$1,$2); - if ($query =~ /[\/\*\\]/) { - next unless (eval { $file =~ /$regex/ }); - return unless &checkEval($@); - } else { - my ($basename) = $file =~ /^.*\/(.*)$/; - next unless (eval { $basename =~ /$regex/ }); - return unless &checkEval($@); - } - next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//); - next if ($front and eval { $file !~ /^\/$query/ }); - return unless &checkEval($@); + last if ($found > 100); + + next unless if (/^\.?\/?(.*?)[\t\s]+(\S+)\n$/); - $contents{$package}{$file} = 1; - $found++; + my ($file,$package) = ("/".$1,$2); + if ($query =~ /[\/\*\\]/) { + next unless (eval { $file =~ /$regex/ }); + return unless &checkEval($@); + } else { + my ($basename) = $file =~ /^.*\/(.*)$/; + next unless (eval { $basename =~ /$regex/ }); + return unless &checkEval($@); } + next if ($query !~ /\.\d\.gz/ and $file =~ /\/man\//); + next if ($front and eval { $file !~ /^\/$query/ }); + return unless &checkEval($@); - last if ($found > 100); + $contents{$package}{$file} = 1; + $found++; } close IN; @@ -274,7 +278,7 @@ sub searchContents { } my $file = "$::param{tempDir}/$::who.txt"; - if (!open(OUT,">$file")) { + if (!open OUT, ">$file") { &::ERROR("Debian: cannot write file for dcc send."); return; } @@ -352,7 +356,7 @@ sub searchAuthor { foreach (keys %urlpackages) { s/##DIST/$dist/g; - if (! -f $_) { + if (! -f "$debian_dir/$_" ) { $bad++; next; } @@ -390,7 +394,7 @@ sub searchAuthor { $package = ""; } else { - &::WARN("invalid line: '$_'."); + &::WARN("debian: invalid line: '$_' (1)."); } } close IN; @@ -454,13 +458,13 @@ sub searchDesc { foreach (keys %urlpackages) { s/##DIST/$dist/g; - if (! -f $_) { + if (! -f "$debian_dir/$_" ) { $bad++; next; } $good++; - $files .= " ".$_; + $files .= " $debian_dir/$_"; } &::DEBUG("deb(2): good = $good, bad = $bad...") if ($debug); @@ -494,10 +498,12 @@ sub searchDesc { &::WARN("sD: package == NULL?"); next; } + $desc{$package} = $desc; $package = ""; + } else { - &::WARN("invalid line: '$_'."); + &::WARN("debian: invalid line: '$_'. (2)"); } } close IN; @@ -512,7 +518,7 @@ sub searchDesc { #### # Usage: &generateIncoming(); sub generateIncoming { - my $pkgfile = "debian/Packages-incoming"; + my $pkgfile = $debian_dir."/Packages-incoming"; my $idxfile = $pkgfile.".idx"; my $stale = 0; $stale++ if (&::isStale($pkgfile.".gz", $refresh)); @@ -523,11 +529,11 @@ sub generateIncoming { ### STATIC URL. my %ftp = &::ftpList("llug.sep.bnl.gov", "/pub/debian/Incoming/"); - if (!open(PKG,">$pkgfile")) { + if (!open PKG, ">$pkgfile") { &::ERROR("cannot write to pkg $pkgfile."); return 0; } - if (!open(IDX,">$idxfile")) { + if (!open IDX, ">$idxfile") { &::ERROR("cannot write to idx $idxfile."); return 0; } @@ -716,7 +722,7 @@ sub infoPackages { if ($incoming) { &::status("iP: info requested and pkg is in incoming, too."); - my %incpkg = &getPackageInfo($query, "debian/Packages-incoming"); + my %incpkg = &getPackageInfo($query, $debian_dir ."/Packages-incoming"); if (scalar keys %incpkg) { $pkg{'info'} .= ". Is in incoming ($incpkg{'file'})."; @@ -785,7 +791,7 @@ sub infoStats { next; } - open(IN,"zcat $file 2>&1 |"); + open(IN, "zcat $file 2>&1 |"); if (! -e $file) { &::DEBUG("deb: iS: $file does not exist."); @@ -843,7 +849,7 @@ sub infoStats { # Usage: &generateIndex(); sub generateIndex { my (@dists) = @_; - &::status("Debian: !!! generateIndex($dists[0]) called !!!"); + &::DEBUG("D: generateIndex($dists[0]) called!"); if (!scalar @dists or $dists[0] eq '') { &::ERROR("gI: no dists to generate index."); return 1; @@ -851,7 +857,7 @@ sub generateIndex { foreach (@dists) { my $dist = &getDistro($_); # incase the alias is returned, possible? - my $idx = "debian/Packages-$dist.idx"; + my $idx = $debian_dir."/Packages-$dist.idx"; # TODO: check if any of the Packages file have been updated then # regenerate it, even if it's not stale. @@ -870,11 +876,11 @@ sub generateIndex { system("cp $idx $idx-old"); } - &::DEBUG("deb: gIndex: calling DebianDownload($dist, ...)."); - &DebianDownload($dist, %urlpackages); + &::DEBUG("deb: gIndex: calling DebianDownload($dist, ...).") if ($debug); + &DebianDownload($dist, &fixDist($dist, %urlpackages) ); &::status("Debian: generating index for '$dist'."); - if (!open(OUT,">$idx")) { + if (!open OUT, ">$idx") { &::ERROR("cannot write to $idx."); return 0; } @@ -882,6 +888,7 @@ sub generateIndex { my $packages; foreach $packages (keys %urlpackages) { $packages =~ s/##DIST/$dist/; + $packages = "$debian_dir/$packages"; if (! -e $packages) { &::ERROR("gIndex: '$packages' does not exist?"); @@ -917,7 +924,7 @@ sub validPackage { &::DEBUG("deb: validPackage($package, $dist) called.") if ($debug); my $error = 0; - while (!open(IN, "debian/Packages-$dist.idx")) { + while (!open IN, $debian_dir."/Packages-$dist.idx") { if ($error) { &::ERROR("Packages-$dist.idx does not exist (#1)."); return; @@ -949,26 +956,22 @@ sub validPackage { sub searchPackage { my ($dist, $query) = &getDistroFromStr($_[0]); - my $file = "debian/Packages-$dist.idx"; + my $file = $debian_dir."/Packages-$dist.idx"; my @files; my $error = 0; - my $warn = 0; - - if ($query =~ tr/A-Z/a-z/) { - $warn++; - } + my $warn = ($query =~ tr/A-Z/a-z/) ? 1 : 0; &::status("Debian: Search package matching '$query' in '$dist'."); - unlink $file if ( -z $file); + unlink $file if ( -z $file ); - while (!open(IN, $file)) { + while (!open IN, $file) { if ($dist eq "incoming") { &::DEBUG("deb: sP: dist == incoming; calling gI()."); &generateIncoming(); } if ($error) { - &::ERROR("could not generate index ($file)!!!"); + &::ERROR("could not generate index ($file)!"); return; } @@ -1061,11 +1064,12 @@ sub fixDist { ### TODO: what should we do if the sar wasn't done. $new{$debian_dir."/".$key} = $val; } + return %new; } sub DebianFind { - ### H-H-H-HACK HACK HACK :) + # HACK! HACK! HACK! my ($str) = @_; my ($dist, $query) = &getDistroFromStr($str); my @results = sort &searchPackage($str); @@ -1082,19 +1086,20 @@ sub DebianFind { } sub debianCheck { - my $dir = "debian/"; my $error = 0; &::status("debianCheck() called."); ### TODO: remove the following loop (check if dir exists before) while (1) { - last if (opendir(DEBIAN, $dir)); + last if (opendir(DEBIAN, $debian_dir)); + if ($error) { &::ERROR("dC: cannot opendir debian."); return; } - mkdir $dir, 0755; + + mkdir $debian_dir, 0755; $error++; } @@ -1103,14 +1108,14 @@ sub debianCheck { while (defined($file = readdir DEBIAN)) { next unless ($file =~ /(gz|bz2)$/); - my $exit = system("gzip -t '$dir/$file'"); + my $exit = system("gzip -t '$debian_dir/$file'"); next unless ($exit); &::DEBUG("deb: hmr... => ".(time() - (stat($file))[8])."'."); next unless (time() - (stat($file))[8] > 3600); &::DEBUG("deb: dC: exit => '$exit'."); - &::WARN("dC: '$dir/$file' corrupted? deleting!"); - unlink $dir."/".$file; + &::WARN("dC: '$debian_dir/$file' corrupted? deleting!"); + unlink $debian_dir."/".$file; $retval++; } @@ -1129,7 +1134,7 @@ sub checkEval { } sub searchDescFE { - &::DEBUG("deb: FE called for searchDesc"); +# &::DEBUG("deb: FE called for searchDesc"); my ($query) = @_; my @list = &searchDesc($query);