Changeset 16765 for trunk/DataStoreServer/scripts/dsreg
- Timestamp:
- Feb 29, 2008, 4:20:09 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/DataStoreServer/scripts/dsreg (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataStoreServer/scripts/dsreg
r16761 r16765 16 16 use PS::IPP::Metadata::Stats; 17 17 use PS::IPP::Metadata::List qw( parse_md_list ); 18 use File::Copy; 18 19 19 20 use PS::IPP::Config qw($PS_EXIT_SUCCESS … … 32 33 my $del; 33 34 34 #my $ds_dir = './dsroot'; 35 my $ds_dir = '/var/www/html/ds/dsroot'; 35 my $ds_dir; 36 36 my $product; 37 37 my $fileset; … … 77 77 unless $add xor $del; 78 78 79 $err .= "Datastore not found at '$ds_dir'.\n" 80 if stat("$ds_dir/index.txt") eq undef; 79 my $ipprc = PS::IPP::Config->new(); # IPP Configuration 80 my $siteConfig = $ipprc->{_siteConfig}; 81 if (!$ds_dir) { 82 $ds_dir = metadataLookupStr($ipprc->{_siteConfig}, 'PSTAMP_DATA_STORE_ROOT'); 83 if (!$ds_dir) { 84 die("data store root not defined"); 85 } 86 } 87 88 89 if (!stat("$ds_dir/index.txt")) { 90 $err .= "Datastore not found at '$ds_dir'.\n" 91 } 81 92 82 93 # bail if any of the above args were improper 83 94 show_usage($err) 84 if defined($err);95 if ($err); 85 96 86 97 $product = shift; … … 91 102 $fileset = shift; 92 103 104 93 105 # 94 106 # run 95 107 # 96 97 # allow write for the mockup98 umask 0011;99 100 my $ipprc = PS::IPP::Config->new(); # IPP Configuration101 my $siteConfig = $ipprc->{_siteConfig};102 108 103 109 my $dbserver = metadataLookupStr($siteConfig, 'DBSERVER'); … … 111 117 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n"; 112 118 113 114 # 115 # delete fileset 116 # 119 my $index_script_name = "$ds_dir/$product/$fileset/index.txt"; 120 117 121 if ($del) { 118 119 die("delete not implemented yet"); 120 121 if (stat("$ds_dir/$product/$fileset/index.txt") == undef) { 122 print "Fileset '$fileset' doesn't exist under $product.\n"; 123 exit(3); 124 } 125 126 # When iterating through the product index below, we rememeber the 127 # fileset and time of the newest (assumes chrono order) fileset that is 128 # not the fileset we're deleting, just in case we have to update the 129 # root index. 130 my $last_fileset; 131 my $last_time; 132 133 134 # Read the product index into a buffer, minus $fileset's entry 135 136 open(IO, "$ds_dir/$product/index.lst") 137 or die("Failed to open '$ds_dir/$product/index.lst' for reading\n"); 138 139 my $buf; 140 141 while (<IO>) { 142 my ($fs, $time, my $tmp) = split(/\|/, $_, 3); 143 $fs =~ s/^\s+|\s+$//; 144 145 # skip the one we're removing 146 next if $fs eq $fileset; 147 148 # record the last one that wasn't the one we're removing 149 $last_fileset = $fs; 150 $last_time = $time; 151 152 $buf .= $_; 153 } 154 155 close(IO); 156 157 158 # Write the new index 159 160 open(IO, ">", "$ds_dir/$product/index.lst") 161 or die("Failed to open '$ds_dir/$product/index.lst' for writing\n"); 162 163 print IO $buf; 164 close(IO); 165 166 167 # Remove the fileset index file 168 169 unlink("$ds_dir/$product/$fileset/index.txt") 170 or die("Failed to delete '$ds_dir/$product/$fileset/index.txt'\n"); 171 172 # Check the root index; if the fileset we just removed was the 173 # 'most_recent' one, then replace it. 174 175 my $doreplace = 0; 176 177 open(IO, "$ds_dir/index.txt") 178 or die("Failed to open '$ds_dir/index.txt' for reading\n"); 179 180 $buf = ''; 181 182 while (<IO>) { 183 my ($prod, $oldrecent, $oldtime, $extra) = split(/\|/, $_, 4); 184 $prod =~ s/^\s+|\s+$//; 185 186 if ($prod ne $product) { 187 $buf .= $_; 188 next; 189 } 190 191 if ($oldrecent ne $fileset) { 192 $buf .= $_; 193 next; 194 } 195 196 $buf .= "$prod|$last_fileset|$last_time|$extra"; 197 $doreplace = 1; 198 } 199 200 close(IO); 201 202 # Write the new root index if needed 203 if ($doreplace) { 204 open(IO, ">", "$ds_dir/index.txt") 205 or die("Failed to open '$ds_dir/index.txt' for writing\n"); 206 207 print IO $buf; 208 close(IO); 209 } 210 211 print "Removed $fileset from $product.\n"; 212 } 213 214 215 # 216 # addding a new fileset 217 # 218 else { 122 # 123 # delete fileset 124 # 125 my $stmt = $dbh->prepare("SELECT prod_id, last_fs FROM dsProduct WHERE prod_name = \'$product\'"); 126 $stmt->execute(); 127 my $prod_row = $stmt->fetchrow_hashref(); 128 my $prod_id = $prod_row->{prod_id}; 129 my $old_last_fs = $prod_row->{last_fs}; 130 131 if (!$prod_id) { 132 die("product $product not found"); 133 } 134 $stmt = $dbh->prepare("SELECT fileset_id,fileset_name FROM dsFileset WHERE fileset_name = '$fileset'" . 135 " AND prod_id = $prod_id"); 136 137 $stmt->execute(); 138 my $fs_row = $stmt->fetchrow_hashref(); 139 140 if (!$fs_row) { 141 print "Fileset '$fileset' not found under $product.\n"; 142 exit 1; 143 } 144 145 # zap the index script 146 unlink("$index_script_name"); 147 148 my $fileset_id = $fs_row->{fileset_id}; 149 150 $dbh->do("DELETE from dsFile where fileset_id = $fileset_id"); 151 $dbh->do("DELETE from dsFileset where fileset_id = $fileset_id"); 152 153 if ($old_last_fs eq $fs_row->{fileset_name}) { 154 # print STDERR "deleting most recent fileset in $product\n"; 155 156 $stmt = $dbh->prepare("SELECT fileset_name from dsFileset " . 157 "WHERE prod_id = $prod_id ORDER BY reg_time DESC LIMIT 1"); 158 $stmt->execute(); 159 my $new_last_fs; 160 my $new_newest = $stmt->fetchrow_hashref(); 161 if ($new_newest) { 162 $new_last_fs = $new_newest->{fileset_name}; 163 } else { 164 $new_last_fs = "none"; 165 } 166 $dbh->do("UPDATE dsProduct SET last_fs = \'$new_last_fs\' WHERE prod_id = $prod_id"); 167 } 168 exit 0; 169 170 } else { 171 # 172 # adding a new fileset 173 # 219 174 my $stmt = $dbh->prepare("SELECT prod_id FROM dsProduct WHERE prod_name = \'$product\'"); 220 175 $stmt->execute(); … … 283 238 } 284 239 240 # create the cgi script index file by making a copy of its parent's 241 if (!copy("$ds_dir/$product/index.txt", $index_script_name)) { 242 die("failed to copy index script to fileset"); 243 } 244 285 245 eval { 286 246 $dbh->{RaiseError} = 1; # raise exception if error occurs … … 332 292 print STDERR "transactionfailed, rolling back error was:\n$@\n"; 333 293 eval {$dbh->rollback();}; 294 unlink($index_script_name); 334 295 exit 1; 335 296 } 336 337 print "Added $fileset to $product.\n";297 298 # print "Added $fileset to $product.\n"; 338 299 339 300 exit 0; … … 356 317 --add Add a new fileset with the given metadata options. 357 318 File information will be read per-line from STDIN, in the form: 358 fileID type chipname319 fileID type [chipname] 359 320 These entries are read until EOF is sent. 360 321 Options: 361 322 362 --dsdir Specify the path to the Datastore (defaults to CWD).323 --dsdir Specify the path to the Datastore 363 324 364 (The following metadata is optional because this is just a mock-up.) 325 $str", 326 -exitval => 2 327 ); 328 329 if (0) { 330 my $saveString = "(The following metadata is not used yet) 365 331 366 332 --date ISO8601 date string. (File timestamp used if not specified.) … … 371 337 --etime Exposure time. 372 338 --filter Filter used. 373 --airmass Air mass. 374 375 $str", 376 -exitval => 2 377 ); 339 --airmass Air mass. "; 340 } 378 341 } 379 342
Note:
See TracChangeset
for help on using the changeset viewer.
