IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 31871


Ignore:
Timestamp:
Jul 13, 2011, 2:00:06 PM (15 years ago)
Author:
watersc1
Message:

Although I'd rather have it in the library, I've implemented a validation block that can be enabled with --validate. This checks md5sums and instance existance, as well as doing further counts of the number of instances.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/bin/neb-stat

    r24644 r31871  
    1616use Pod::Usage qw( pod2usage );
    1717
    18 my ($server);
     18use Digest::MD5;
     19use URI;
     20
     21my ($validate,$server);
    1922
    2023$server = $ENV{'NEB_SERVER'} unless $server;
     
    2225GetOptions(
    2326    'server|s=s'     => \$server,
     27    'validate'         => \$validate,
    2428) || pod2usage( 2 );
    2529
     
    4448die "no instances found" unless $instances;   
    4549
     50my $user_copies = $neb->getxattr($key, "user.copies");
     51unless(defined($user_copies)) {
     52    $user_copies = 1;
     53}
     54
     55my @validation;
     56my %md5sum_uniq;
     57my $existing_copies = 0;
     58if (defined $validate) {
     59    my @existance;
     60    my @md5sums;
     61    my @files = map {URI->new($_)->file if $_} @$instances;
     62
     63    for (my $i = 0; $i <= $#files; $i++) {
     64        if (-e $files[$i]) {
     65            $existance[$i] = 1;
     66            $existing_copies++;
     67            my $fh;
     68            open($fh,$files[$i]);
     69            $md5sums[$i] = Digest::MD5->new->addfile($fh)->hexdigest;
     70            $md5sum_uniq{$md5sums[$i]} = 1;
     71            close($fh);
     72        }
     73        else {
     74            $existance[$i] = 0;
     75            $md5sums[$i] = 'NON-EXISTANT';
     76            $md5sum_uniq{$md5sums[$i]} = 1;
     77        }
     78        $validation[$i] = sprintf("% 3d %32s %s",
     79                                  $existance[$i],
     80                                  $md5sums[$i],
     81                                  ${ $instances }[$i]);
     82    }
     83}
     84
    4685no warnings qw(uninitialized);
    47 print
    48     "object id:             ", @$stat[0], "\n",
    49     "key:                   ", @$stat[1], "\n",
    50     "read lock:             ", @$stat[2], "\n",
    51     "write lock:            ", @$stat[3], "\n",
    52     "epoch:                 ", @$stat[4], "\n",
    53     "mtime:                 ", @$stat[5], "\n",
    54     "available instances:   ", @$stat[6], "\n",
    55     "total instances:       ", @$stat[7], "\n",
    56     "instance location:\n", " " x 4,
    57     join("\n" . " " x 4, @$instances), "\n";
     86if (defined $validate) {
     87    print
     88        "object id:             ", @$stat[0], "\n",
     89        "key:                   ", @$stat[1], "\n",
     90        "read lock:             ", @$stat[2], "\n",
     91        "write lock:            ", @$stat[3], "\n",
     92        "epoch:                 ", @$stat[4], "\n",
     93        "mtime:                 ", @$stat[5], "\n",
     94        "md5sum count:          ", scalar(keys %md5sum_uniq), "\n",
     95        "requested instances:   ", $user_copies, "\n",
     96        "available instances:   ", @$stat[6], "\n",
     97        "existing instances:    ", $existing_copies, "\n",
     98        "total instances:       ", @$stat[7], "\n",
     99       
     100        "instance location:\n", " " x 4,
     101        join("\n" . " " x 4, @validation), "\n";
     102}
     103else {
     104    print
     105        "object id:             ", @$stat[0], "\n",
     106        "key:                   ", @$stat[1], "\n",
     107        "read lock:             ", @$stat[2], "\n",
     108        "write lock:            ", @$stat[3], "\n",
     109        "epoch:                 ", @$stat[4], "\n",
     110        "mtime:                 ", @$stat[5], "\n",
     111        "available instances:   ", @$stat[6], "\n",
     112        "requested instances:   ", $user_copies, "\n",
     113        "total instances:       ", @$stat[7], "\n",
     114       
     115        "instance location:\n", " " x 4,
     116        join("\n" . " " x 4, @$instances), "\n";
     117}
     118
    58119
    59120__END__
Note: See TracChangeset for help on using the changeset viewer.