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