Changeset 17552 for trunk/DataStore
- Timestamp:
- May 6, 2008, 5:05:03 PM (18 years ago)
- Location:
- trunk/DataStore
- Files:
-
- 4 edited
-
Build.PL (modified) (1 diff)
-
Changes (modified) (1 diff)
-
lib/DataStore/File.pm (modified) (7 diffs)
-
scripts/dsget (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStore/Build.PL
r15266 r17552 12 12 'Data::Validate::URI' => '0.01', 13 13 'Digest::MD5::File' => '0.03', 14 'IPC::Cmd' => '0.36', 14 15 'File::Basename' => 0, 15 16 'File::Temp' => '0.16', -
trunk/DataStore/Changes
r17534 r17552 2 2 3 3 0.07 4 - add support for checksumming compressed fits files 4 5 - Change DateStore::File to handle passing args to LWP::UserAgent 5 6 - add dsget --timeout option -
trunk/DataStore/lib/DataStore/File.pm
r17534 r17552 1 1 # Copyright (C) 2006 Joshua Hoblitt 2 2 # 3 # $Id: File.pm,v 1.1 7 2008-05-06 02:35:22jhoblitt Exp $3 # $Id: File.pm,v 1.18 2008-05-07 03:05:03 jhoblitt Exp $ 4 4 5 5 package DataStore::File; … … 17 17 use DataStore::Utils qw( $STD_FIELD $BYTE_FIELD $MD5_FIELD %KNOWN_FILE_TYPES ); 18 18 use Digest::MD5::File qw( file_md5_hex ); 19 use File::Basename qw( basename ); 20 use File::Temp (); 19 21 use File::stat; 20 use Params::Validate qw( validate SCALAR ARRAYREF ); 22 use IPC::Cmd 0.36 qw( can_run run ); 23 use Params::Validate qw( validate SCALAR ARRAYREF UNDEF ); 21 24 22 25 use vars qw( @BASE_FIELDS ); 23 26 24 @BASE_FIELDS = qw( fileid bytes md5sum type extra );27 @BASE_FIELDS = qw( fileid bytes md5sum type extra compressed ); 25 28 26 29 __PACKAGE__->mk_accessors(@BASE_FIELDS); … … 158 161 optional => 1, 159 162 }, 163 compressed => { 164 type => SCALAR | UNDEF, 165 optional => 1, 166 }, 160 167 }, 161 168 ); … … 228 235 }, 229 236 ); 237 238 my $verbose = 0; 230 239 231 240 # make request … … 241 250 242 251 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 243 282 # check size 244 283 if (defined $self->bytes) { 245 my $size = stat($ filename)->size;284 my $size = stat($chk_file)->size; 246 285 if (! ($self->bytes == $size)) { 247 286 unlink $filename; … … 251 290 # set the filename to undef to indicate an error 252 291 $filename = undef; 292 } else { 293 carp "uri: ", $self->uri, 294 " - expected size: ", $self->bytes, 295 " got: ", $size 296 if $verbose; 253 297 } 254 298 } 255 299 256 300 if (defined $filename and defined $self->md5sum) { 257 my $md5 = file_md5_hex($ filename);301 my $md5 = file_md5_hex($chk_file); 258 302 if (! ($self->md5sum eq $md5)) { 259 303 unlink $filename; … … 263 307 # set the filename to undef to indicate an error 264 308 $filename = undef; 309 } else { 310 carp "uri: ", $self->uri, 311 " - expected md5: ", $self->md5sum, 312 " got: ", $md5 313 if $verbose; 265 314 } 266 315 } -
trunk/DataStore/scripts/dsget
r17551 r17552 3 3 # Copyright (C) 2006-2008 Joshua Hoblitt 4 4 # 5 # $Id: dsget,v 1.2 2 2008-05-07 01:54:20jhoblitt Exp $5 # $Id: dsget,v 1.23 2008-05-07 03:05:03 jhoblitt Exp $ 6 6 7 7 use strict; … … 76 76 $p{bytes} = $bytes if defined $bytes; 77 77 $p{md5sum} = $md5 if defined $md5; 78 $p{compressed} = 1 if defined $compress; 78 79 79 80 my $tmp;
Note:
See TracChangeset
for help on using the changeset viewer.
