IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23902


Ignore:
Timestamp:
Apr 17, 2009, 10:44:22 AM (17 years ago)
Author:
bills
Message:

allow the registration of empty filesets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStoreServer/scripts/dsreg

    r20293 r23902  
    3131my $fileset;
    3232my $filelist;
     33my $empty;
    3334
    3435my $fstype;
     
    6465        'product=s'     =>      \$product,
    6566        'list=s'        =>      \$filelist,
     67        'empty'         =>      \$empty,
    6668        'type=s'        =>      \$fstype,
    6769        'datapath=s'    =>      \$datapath,
     
    9597    $fileset = $add;
    9698    $err .= "--type is required\n" unless defined $fstype;
    97     $err .= "--list is required\n" unless defined $filelist;
     99    $err .= "--list is required\n" unless defined $filelist or $empty;
    98100    if ($linkfiles and $copyfiles) {
    99101        $err .= "only one of --link and --copy is allowed\n";
     
    251253    }
    252254
     255
    253256    # Note: There is a race condition here. Somebody could sneak in now and add a fileset with
    254257    # fileset_name = $fileset. So later we'll check again that only one fileset with the name exists
    255258
    256 
    257     my $in;
    258     if ($filelist eq "-") {
    259         $in = *STDIN;
    260     } else {
    261         open $in, "<$filelist" or die  "cannot open filelist file $filelist\n";
    262     }
    263 
    264     my $lineno = 0;
     259    ## create the fileset directory
     260    if (! -e $fileset_dir) {
     261        if (!mkdir $fileset_dir) {
     262            die("failed trying to create fileset directory $fileset_dir");
     263        }
     264    }
     265
    265266    my @files;
    266     while (<$in>) {
    267         chomp;
    268         $lineno++;
    269 
    270         my $filename;
    271         my $bytes;
    272         my $md5sum;
    273         my $filetype;
    274 
    275         my @fields = split /\|/;
    276         if (@fields < 4) {
    277             die "malformed input line at $filelist line $lineno: $_\n";
    278         }
    279         $filename = shift @fields;
    280         $bytes    = shift @fields;  # if this is null it will be calculated below
    281         $md5sum   = shift @fields;  # if this is null it will be calculated below
    282         $filetype = shift @fields;
    283 
    284         # make sure the length of the type specific columns is 8
    285         while (@fields < 8) {
    286             push @fields, undef;
    287         }
    288         my $ts_cols = [@fields];
    289 
    290         my $hashref = {
    291             'file'      => $filename,
    292             'bytes'     => $bytes,
    293             'md5sum'    => $md5sum,
    294             'type'      => $filetype,
    295             'ts_cols'   => $ts_cols,
    296         };
    297 
    298         push @files, $hashref;
    299     }
    300 
    301     die("empty filelist\n") if (@files == 0);
    302 
    303     # Prepare the fileset directory
    304     if ($linkfiles or $copyfiles) {
    305         ## create the fileset directory
    306         if (! -e $fileset_dir) {
    307             if (!mkdir $fileset_dir) {
    308                 die("failed trying to create fileset directory $fileset_dir");
    309             }
    310         }
    311         eval {
    312             ## then copy or symlink the files into place
    313             foreach my $ref (@files) {
    314                 my $src = (defined $abspath ? '' : "$datapath/") . "$ref->{file}";
    315                 my $filename = fileparse($ref->{file}, ());
    316                 my $dest = "$fileset_dir/$filename";
    317 
    318                 if ($linkfiles) {
    319                     if (! symlink $src, $dest) {
    320                         die("failed trying to link $src to $dest");
    321                     }
    322                 } else {
    323                     if (!copy($src, $dest)) {
    324                         die("copy($src, $dest) failed");
     267    if (!$empty) {
     268        my $in;
     269        if ($filelist eq "-") {
     270            $in = *STDIN;
     271        } else {
     272            open $in, "<$filelist" or die  "cannot open filelist file $filelist\n";
     273        }
     274
     275        my $lineno = 0;
     276        while (<$in>) {
     277            chomp;
     278            $lineno++;
     279
     280            my $filename;
     281            my $bytes;
     282            my $md5sum;
     283            my $filetype;
     284
     285            my @fields = split /\|/;
     286            if (@fields < 4) {
     287                die "malformed input line at $filelist line $lineno: $_\n";
     288            }
     289            $filename = shift @fields;
     290            $bytes    = shift @fields;  # if this is null it will be calculated below
     291            $md5sum   = shift @fields;  # if this is null it will be calculated below
     292            $filetype = shift @fields;
     293
     294            # make sure the length of the type specific columns is 8
     295            while (@fields < 8) {
     296                push @fields, undef;
     297            }
     298            my $ts_cols = [@fields];
     299
     300            my $hashref = {
     301                'file'      => $filename,
     302                'bytes'     => $bytes,
     303                'md5sum'    => $md5sum,
     304                'type'      => $filetype,
     305                'ts_cols'   => $ts_cols,
     306            };
     307
     308            push @files, $hashref;
     309        }
     310
     311        die("empty filelist\n") if (@files == 0);
     312
     313        # Prepare the fileset directory
     314        if ($linkfiles or $copyfiles) {
     315            eval {
     316                ## then copy or symlink the files into place
     317                foreach my $ref (@files) {
     318                    my $src = (defined $abspath ? '' : "$datapath/") . "$ref->{file}";
     319                    my $filename = fileparse($ref->{file}, ());
     320                    my $dest = "$fileset_dir/$filename";
     321
     322                    if ($linkfiles) {
     323                        if (! symlink $src, $dest) {
     324                            die("failed trying to link $src to $dest");
     325                        }
     326                    } else {
     327                        if (!copy($src, $dest)) {
     328                            die("copy($src, $dest) failed");
     329                        }
    325330                    }
    326331                }
    327             }
    328         };
    329         if ($@) { # an error occured
    330             print STDERR "error preparing the fileset directory: $@\n";
    331 
    332             if (!$no_cleanup && system "rm -r $fileset_dir") {
    333                 die("failed to remove $fileset_dir");
    334             }
    335             exit $PS_EXIT_UNKNOWN_ERROR;
    336         }
    337     }
    338 
    339     # now calculate the md5sum and file size if they weren't provided
    340     foreach my $file (@files) {
    341         my $filename = fileparse($file->{file}, ());
    342         my $path = "$fileset_dir/$filename";
    343         if (! -e $path ) {
    344             die "file $path not found";
    345         }
    346         if (!$file->{bytes}) {
    347             my @finfo = stat($path);
    348             unless (@finfo) {
    349                 die ("can't stat $path");
    350             }
    351             $file->{bytes}  = $finfo[7];
    352         }
    353         if (!$file->{md5sum}) {
    354             # Get MD5 sum
    355             $file->{md5sum} = file_md5_hex($path);
     332            };
     333            if ($@) { # an error occured
     334                print STDERR "error preparing the fileset directory: $@\n";
     335
     336                if (!$no_cleanup && system "rm -r $fileset_dir") {
     337                    die("failed to remove $fileset_dir");
     338                }
     339                exit $PS_EXIT_UNKNOWN_ERROR;
     340            }
     341        }
     342
     343        # now calculate the md5sum and file size if they weren't provided
     344        foreach my $file (@files) {
     345            my $filename = fileparse($file->{file}, ());
     346            my $path = "$fileset_dir/$filename";
     347            if (! -e $path ) {
     348                die "file $path not found";
     349            }
     350            if (!$file->{bytes}) {
     351                my @finfo = stat($path);
     352                unless (@finfo) {
     353                    die ("can't stat $path");
     354                }
     355                $file->{bytes}  = $finfo[7];
     356            }
     357            if (!$file->{md5sum}) {
     358                # Get MD5 sum
     359                $file->{md5sum} = file_md5_hex($path);
     360            }
    356361        }
    357362    }
Note: See TracChangeset for help on using the changeset viewer.