Changeset 25027 for branches/pap/ippScripts/scripts/receive_fileset.pl
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/receive_fileset.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/ippScripts/scripts/receive_fileset.pl
r23894 r25027 21 21 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 22 22 use Pod::Usage qw( pod2usage ); 23 use File::Temp qw( tempfile ); 24 use Carp; 23 25 24 26 # Look for programs we need … … 32 34 33 35 # Parse the command-line arguments 34 my ( $fileset_id, $source, $product, $fileset, $dbname, $verbose, $no_update );36 my ( $fileset_id, $source, $product, $fileset, $dbname, $verbose, $no_update, $save_temps ); 35 37 36 38 GetOptions( … … 42 44 'verbose' => \$verbose, # Print to stdout 43 45 'no-update' => \$no_update, # Don't update the database? 46 'save-temps' => \$save_temps, # keep temp files 44 47 ) or pod2usage( 2 ); 45 48 … … 52 55 defined $fileset; 53 56 54 # Get list of files 55 my @files = (); # Files to add 57 # Get list of files, sanity check and then write it to a temporary file 58 my $numFiles = 0; 59 my ($listFile, $listName) = tempfile("/tmp/$product.$fileset.list.XXXX", UNLINK => !$save_temps); 56 60 { 57 61 my $uri = "$source/$product/$fileset"; # URI for datastore fileset … … 61 65 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 62 66 run(command => $command, verbose => $verbose); 63 die "Unable to get fileset listing from $uri\n"unless $success;67 &my_die( "Unable to get fileset listing from $uri\n", $fileset_id, $error_code) unless $success; 64 68 65 69 # Get files … … 69 73 next unless $line =~ /\S+/; 70 74 my @fields = split(/\s+/, $line); # Fields in line 71 my $file = $fields[1]; # Name of file 72 push @files, $file if defined $file; 75 &my_die( "too few columns in fileset list entry: $line\n", $fileset_id, $PS_EXIT_DATA_ERROR) unless scalar @fields >= 6; 76 77 print $listFile "FILE$numFiles\tMETADATA\n"; 78 79 print $listFile "\turi\t\tSTR\t" . $fields[0] . "\n"; 80 print $listFile "\tfile\t\tSTR\t" . $fields[1] . "\n"; 81 print $listFile "\tbytes\t\tS64\t" . $fields[2] . "\n"; 82 print $listFile "\tmd5sum\t\tSTR\t" . $fields[3] . "\n"; 83 print $listFile "\tfile_type\tSTR\t" . $fields[4] . "\n"; 84 print $listFile "\tcomponent\tSTR\t" . $fields[5] . "\n"; 85 86 print $listFile "END\n"; 87 $numFiles++; 73 88 } 89 close $listFile; 74 90 } 75 91 76 92 # Add files 77 if (scalar @files > 0) { 93 my $new_state; 94 if ($numFiles > 0) { 95 $new_state = "listed"; 78 96 my $command = "receivetool -addfile"; # Command to execute 79 97 $command .= " -fileset_id $fileset_id"; 80 $command .= " -file " . join(' -file ', @files);98 $command .= " -file_list $listName"; 81 99 $command .= " -dbname $dbname" if defined $dbname; 82 100 … … 84 102 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 85 103 run(command => $command, verbose => $verbose); 86 die "Unable to add file for fileset $fileset\n" unless $success; 104 &my_die( "Unable to add file list for fileset $fileset\n", $fileset_id, $error_code) unless $success; 105 } 106 } else { 107 print STDERR "fileset $fileset has no files\n" if $verbose; 108 $new_state = "full"; 109 } 110 111 { 112 my $command = "receivetool -updatefileset"; # Command to execute 113 $command .= " -fileset_id $fileset_id"; 114 $command .= " -set_state $new_state"; 115 $command .= " -dbname $dbname" if defined $dbname; 116 117 unless (defined $no_update) { 118 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 119 run(command => $command, verbose => $verbose); 120 &my_die( "Unable to set state to $new_state for fileset $fileset\n", $fileset_id, $error_code) unless $success; 87 121 } 88 122 } 89 123 124 sub my_die { 125 my $msg = shift; # Exit message 126 my $fileset_id = shift; # File identifier 127 my $fault = shift; # Fault code 128 129 $fault = $PS_EXIT_PROG_ERROR unless defined $fault; 130 131 carp($msg); 132 if (not $no_update) { 133 my $command = "$receivetool -updatefileset"; 134 $command .= " -fileset_id $fileset_id"; 135 $command .= " -fault $fault"; 136 $command .= " -dbname $dbname" if defined $dbname; 137 138 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 139 run(command => $command, verbose => $verbose); 140 die "Unable to set fault to $fault for fileset $fileset\n" unless $success; 141 } 142 exit $fault; 143 } 90 144 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
