From: minima Date: Thu, 11 Jul 2002 16:47:36 +0000 (+0000) Subject: make export_user much more robust X-Git-Tag: R_1_50~27 X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?p=spider.git;a=commitdiff_plain;h=0e8259381a4d4f4ea9059cdabc0cc4c88e637a99 make export_user much more robust --- diff --git a/Changes b/Changes index bb156973..eb908dad 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,10 @@ Digest::SHA1 and any dependant packages to run this release. HOWEVER tempted you are, please don't set/newprotocol on any nodes. It won't work. 2. Make the cluster node registered on from startup (from Mark HB9DBM). +3. Make the 'export_users' process *MUCH* more robust. It should now accept +funny characters and not rely on an absolutely 'perfect' user file to work. +Errors are displayed (and logged if done from the cluster) and then ignored. +Invalid callsigns are removed. 09Jul02======================================================================= 1. make the is_qra more accurate (from Mark HB9DBM). 04Jul02======================================================================= diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 1e06cd3c..84a56949 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -14,6 +14,7 @@ use Data::Dumper; use Fcntl; use IO::File; use DXDebug; +use DXUtil; use strict; @@ -325,10 +326,11 @@ sub export rename "$fn", "$fn.o" if -e "$fn"; my $count = 0; + my $err = 0; my $fh = new IO::File ">$fn" or return "cannot open $fn ($!)"; if ($fh) { - my $ref = 0; my $key = 0; + my $val = undef; my $action; my $t = scalar localtime; print $fh q{#!/usr/bin/perl @@ -376,19 +378,46 @@ if (@ARGV) { DXUser->del_file($main::userfn); DXUser->init($main::userfn, 1); - -%u = ( - }; - - for ($action = R_FIRST; !$dbm->seq($key, $ref, $action); $action = R_NEXT) { - print $fh "'$key' => q{$ref},\n"; - ++$count; +%u = (); +my $count = 0; +my $err = 0; +while () { + chomp; + my @f = split /\t/; + my $ref = decode($f[1]); + if ($ref) { + $ref->put(); + $count++; + } else { + print "# Error: $f[0]\t$f[1]\n"; + $err++ + } +} +DXUser->sync; DXUser->finish; +print "There are $count user records and $err errors\n"; +}; + print $fh "__DATA__\n"; + + for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) { + if (!is_callsign($key) || $key =~ /^0/) { + Log('DXCommand', "Export Error: $key\t$val"); + $dbm->del($key); + ++$err; + next; + } + my $ref = decode($val); + if ($ref) { + print $fh "$key\t" . $ref->encode . "\n"; + ++$count; + } else { + Log('DXCommand', "Export Error: $key\t$val"); + $dbm->del($key); + ++$err; + } } - print $fh ");\n#\nprint \"there were $count records\\n\";\n#\n"; - print $fh "DXUser->sync; DXUser->finish;\n#\n"; $fh->close; } - return $count; + return "$count Users $err Errors ('sh/log Export' for details)"; } #