Changeset 16872 for trunk/DataStoreServer/scripts/dsreg
- Timestamp:
- Mar 7, 2008, 12:06:52 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/DataStoreServer/scripts/dsreg (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStoreServer/scripts/dsreg
r16867 r16872 161 161 162 162 if (!$fs_row) { 163 print "Fileset '$fileset' not found under $product.\n";163 print STDERR "Fileset '$fileset' not found under $product.\n"; 164 164 exit 1; 165 165 } … … 201 201 # 202 202 203 # make a string out of the product specifc column values provided204 my $prodcolstr = make_prodcol_str($ps0, $ps1, $ps2, $ps3, $ps4, $ps5, $ps6, $ps7);205 203 206 204 my $stmt = $dbh->prepare("SELECT prod_id FROM dsProduct WHERE prod_name = \'$product\'"); … … 220 218 } 221 219 220 # Note: There is a race condition here. Somebody could sneak in now and add a fileset with 221 # fileset_name = $fileset. So later we'll check again that only one fileset with the name exists 222 222 223 # Read file data from STDIN 224 # XXX: Perhaps allow this to come from a file 223 225 224 226 my $lineno = 0; … … 318 320 # create the cgi script index.txt by making a copy of its parent's 319 321 if (!copy("$ds_dir/$product/index.txt", $index_script_name)) { 322 cleanup(); 320 323 die("failed to copy index script to file set"); 321 324 } … … 326 329 $dbh->{AutoCommit} = 0; 327 330 331 # note the resulting prodcolstr begins with a comma 332 my $prodcolstr = make_prodcol_str($ps0, $ps1, $ps2, $ps3, $ps4, $ps5, $ps6, $ps7); 333 328 334 my $qstring = "INSERT into dsFileset" . 329 335 " (prod_id, fileset_name, reg_time, type," . 330 336 " prod_col_0, prod_col_1, prod_col_2, prod_col_3, prod_col_4, prod_col_5, " . 331 337 " prod_col_6, prod_col_7)" . 332 # note prodcolstr begins with a comma333 338 " VALUES($prod_id, \'$fileset\', UTC_TIMESTAMP(), \'$fstype\' $prodcolstr)"; 339 334 340 $count = $dbh->do($qstring); 335 341 if ($count == 0E0) { … … 339 345 my $fileset_id = $dbh->last_insert_id(undef, undef, undef, undef); 340 346 341 # print STDERR "Inserted fileset_id $fileset_id\n"; 347 # make sure that no-one got in and created a fileset with this name while we were busy 348 $count = $dbh->do("SELECT fileset_id FROM dsFileset WHERE fileset_name = '$fileset'" . 349 " AND prod_id = $prod_id"); 350 if ($count > 1) { 351 die("Fileset '$fileset' already exists under $product."); 352 } 342 353 343 354 foreach my $ref (@files) { … … 371 382 print STDERR "transactionfailed, rolling back error was:\n$@\n"; 372 383 eval {$dbh->rollback();}; 373 unlink($index_script_name);384 cleanup(); 374 385 exit 1; 375 386 } 376 377 # print "Added $fileset to $product.\n";378 387 379 388 exit 0; … … 431 440 return $string; 432 441 } 442 443 sub cleanup { 444 445 if ($linkfiles or $copyfiles) { 446 if (system "rm -r $fileset_dir") { 447 print STDERR "failed to remove $fileset_dir"; 448 } 449 } else { 450 unlink($index_script_name); 451 } 452 }
Note:
See TracChangeset
for help on using the changeset viewer.
