Tool for running tdx-util

Jeffrey M. Vinocur jeff at litech.org
Mon Oct 28 01:21:33 UTC 2002



I keep the groups I care about in tradspool, and everything else in CNFS.  
After a crash, I really don't care if a few articles from CNFS go missing.  
But I do want to rebuild overview for those groups I have in tradspool.  
So `makehistory -O` is overkill, but tdx-util only does a single group at 
a time (and can't easily be scripted with xargs(1) because it needs the 
newsgroup name and the path.


Here's a little script that provides tdx-util with slightly more 
intelligence than it has to begin with.  Worth putting in contrib?



#!/usr/bin/perl -w
require "/usr/local/news/lib/innshellvars.pl" ;

# Written by Jeffrey M. Vinocur <jeff at litech.org>
# This work is hereby placed in the public domain by its author.
#
# Usage: tdx-rebuild.pl [pattern]
#
#     Iteratively spawns `tdx-util -R -n` for each group found in
#     tradspool storage in $patharticles.  If "pattern" is given, only
#     groups matching the pattern (as a Perl regex) are considered for
#     rebuilding.
#
#
# Caution:  This may not do what you intended for groups that have
#           articles stored in multiple storage methods, since tdx-util
#           ignores all articles not found in tradspool.


use strict;

my $regex = shift || '^';

open(ACTIVE, '<', $inn::active) || die "Opening $inn::active";

my $tdxutil = $inn::pathbin . '/tdx-util';
die "$tdxutil not executable" unless -x $tdxutil;

my ($group, $path);
my ($tradspool, $notfound, $skipped) = (0, 0, 0);

my @args = ($tdxutil, '-R', undef, '-n', undef);

while( <ACTIVE> ) {
  $group = (split())[0];

  unless( $group =~ /$regex/o ) {
    $skipped++;
    next;
  }

  ($path = $group) =~ tr{.}{/};
  $path = $inn::patharticles . '/' . $path;

  if( -d $path ) {
    $tradspool++;
    $args[2] = $path;
    $args[4] = $group;
    print "Rebuilding\t$group\n";
    system(@args) == 0 || &problem(@args);
  } else {
    $notfound++;
  }
}
close ACTIVE;

print "Skipped $skipped groups not matching pattern \"$regex\"\n" if $skipped;
print "Skipped $notfound groups not visible in tradspool\n";
print "Rebuilt $tradspool groups from data in $inn::patharticles\n";

exit 0;

sub problem {
  my ($status, $signal, $core) = ($? >> 8, $? & 127, $? & 128);
  print STDERR "Failed executing:  $!\n" if $? < 0;
  print STDERR "Caught signal $signal\n" if $signal;
  print STDERR "Dumped core\n" if $core;
  die "Non-zero ($status) return from \"@_\"" if $status;
  die "Problems executing \"@_\"";
}


-- 
Jeffrey M. Vinocur
jeff at litech.org



More information about the inn-patches mailing list