IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17552 for trunk/DataStore


Ignore:
Timestamp:
May 6, 2008, 5:05:03 PM (18 years ago)
Author:
jhoblitt
Message:

add support for checksumming compressed fits files

Location:
trunk/DataStore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStore/Build.PL

    r15266 r17552  
    1212        'Data::Validate::URI'   => '0.01',
    1313        'Digest::MD5::File'     => '0.03',
     14        'IPC::Cmd'              => '0.36',
    1415        'File::Basename'        => 0,
    1516        'File::Temp'            => '0.16',
  • trunk/DataStore/Changes

    r17534 r17552  
    22
    330.07
     4    - add support for checksumming compressed fits files
    45    - Change DateStore::File to handle passing args to LWP::UserAgent
    56    - add dsget --timeout option
  • trunk/DataStore/lib/DataStore/File.pm

    r17534 r17552  
    11# Copyright (C) 2006  Joshua Hoblitt
    22#
    3 # $Id: File.pm,v 1.17 2008-05-06 02:35:22 jhoblitt Exp $
     3# $Id: File.pm,v 1.18 2008-05-07 03:05:03 jhoblitt Exp $
    44
    55package DataStore::File;
     
    1717use DataStore::Utils qw( $STD_FIELD $BYTE_FIELD $MD5_FIELD %KNOWN_FILE_TYPES );
    1818use Digest::MD5::File qw( file_md5_hex );
     19use File::Basename qw( basename );
     20use File::Temp ();
    1921use File::stat;
    20 use Params::Validate qw( validate SCALAR ARRAYREF );
     22use IPC::Cmd 0.36 qw( can_run run );
     23use Params::Validate qw( validate SCALAR ARRAYREF UNDEF );
    2124
    2225use vars qw( @BASE_FIELDS );
    2326
    24 @BASE_FIELDS = qw( fileid bytes md5sum type extra );
     27@BASE_FIELDS = qw( fileid bytes md5sum type extra compressed );
    2528
    2629__PACKAGE__->mk_accessors(@BASE_FIELDS);
     
    158161                optional    => 1,
    159162            },
     163            compressed => {
     164                type        => SCALAR | UNDEF,
     165                optional    => 1,
     166            },
    160167        },
    161168    );
     
    228235        },
    229236    );
     237
     238    my $verbose = 0;
    230239
    231240    # make request
     
    241250
    242251    if ($response->is_success) {
     252        my $funpack;
     253        if ($self->compressed) {
     254            $funpack = can_run('funpack')
     255                or warn "can't find funpack -- unable to compute checksum";
     256        }
     257
     258        my $chk_file = $filename;
     259        # so that the tmp file stays in scope until we're done processing
     260        my $tmp;
     261        if ($funpack) {
     262            $tmp = File::Temp->new(
     263                DIR         => '/tmp',
     264                TEMPLATE    => basename($filename) . '.XXXXXXXX',
     265                SUFFIX      => '.tmp',
     266                UNLINK      => 1,
     267            );
     268
     269            my $unpacked_path = $tmp->filename;
     270
     271            my $command = "$funpack -S -C $filename > $unpacked_path";
     272            my ($success, $status, $full_buf, $stdout_buf, $stderr_buf)
     273                = run(command => $command, verbose => $verbose);
     274
     275            unless ($success) {
     276                die "funpack returned exit status $status\n";
     277            }
     278
     279            $chk_file = $unpacked_path;
     280        }
     281
    243282        # check size
    244283        if (defined $self->bytes) {
    245             my $size = stat($filename)->size;
     284            my $size = stat($chk_file)->size;
    246285            if (! ($self->bytes == $size)) {
    247286                unlink $filename;
     
    251290                # set the filename to undef to indicate an error
    252291                $filename = undef;
     292            } else {
     293                carp "uri: ", $self->uri,
     294                     " - expected size: ", $self->bytes,
     295                     " got: ", $size
     296                if $verbose;
    253297            }
    254298        }
    255299
    256300        if (defined $filename and defined $self->md5sum) {
    257             my $md5 = file_md5_hex($filename);
     301            my $md5 = file_md5_hex($chk_file);
    258302            if (! ($self->md5sum eq $md5)) {
    259303                unlink $filename;
     
    263307                # set the filename to undef to indicate an error
    264308                $filename = undef;
     309            } else {
     310                carp "uri: ", $self->uri,
     311                     " - expected md5: ", $self->md5sum,
     312                     " got: ", $md5
     313                if $verbose;
    265314            }
    266315        }
  • trunk/DataStore/scripts/dsget

    r17551 r17552  
    33# Copyright (C) 2006-2008  Joshua Hoblitt
    44#
    5 # $Id: dsget,v 1.22 2008-05-07 01:54:20 jhoblitt Exp $
     5# $Id: dsget,v 1.23 2008-05-07 03:05:03 jhoblitt Exp $
    66
    77use strict;
     
    7676$p{bytes} = $bytes if defined $bytes;
    7777$p{md5sum} = $md5 if defined $md5;
     78$p{compressed} = 1 if defined $compress;
    7879
    7980my $tmp;
Note: See TracChangeset for help on using the changeset viewer.