IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 5, 2008, 2:17:16 PM (18 years ago)
Author:
Paul Price
Message:

Adding option for absolute path.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStoreServer/scripts/dsreg

    r17895 r17948  
    1515use PS::IPP::Metadata::List qw( parse_md_list );
    1616use File::Copy;
     17use File::Basename;
    1718
    1819use PS::IPP::Config qw($PS_EXIT_SUCCESS
     
    3738my $copyfiles;      # if set, copy files from this directory to the Data Store fileset
    3839my $datapath;       # source for files required if $linkfiles or $copyfiles
     40my $abspath;                    # Path specified is absolute
    3941
    4042my $dbname;         # Database name
     
    6062        'type=s'        =>      \$fstype,
    6163        'datapath=s'    =>      \$datapath,
     64        'abspath'       =>      \$abspath,
    6265        'link'          =>      \$linkfiles,
    6366        'copy'          =>      \$copyfiles,
     
    9295        $err .= "only one of --link and --copy is allowed\n";
    9396    }
    94     if (($linkfiles or $copyfiles) and !$datapath) {
     97    if (($linkfiles or $copyfiles) and !$datapath and !$abspath) {
    9598        $err .= "need to specify datapath with --link or --copy\n";
    9699    }
     
    293296            ## then copy or symlink the files into place
    294297            foreach my $ref (@files) {
    295                 my $src = "$datapath/$ref->{file}";
    296                 my $dest = "$fileset_dir/$ref->{file}";
     298                my $src = (defined $abspath ? '' : "$datapath/") . "$ref->{file}";
     299                my $filename = fileparse($ref->{file}, ());
     300                my $dest = "$fileset_dir/$filename";
    297301
    298302                if ($linkfiles) {
     
    319323    # now calculate the md5sum and file size
    320324    foreach my $file (@files) {
    321 
    322         my $path = "$fileset_dir/$file->{file}";
     325        my $filename = fileparse($file->{file}, ());
     326        my $path = "$fileset_dir/$filename";
    323327        my @finfo = stat("$path");
    324328
     
    364368
    365369        foreach my $ref (@files) {
     370            my $filename = fileparse($ref->{file}, ());
    366371            my $query = "INSERT INTO dsFile" . 
    367372                    " (fileset_id, file_id, file_name, bytes, md5sum, type," .
     
    371376
    372377            my $aref = $ref->{ts_cols};
    373             my $do_args =  [($ref->{file}, $ref->{bytes}, $ref->{md5sum}, $ref->{type}), @$aref];
     378            my $do_args =  [($filename, $ref->{bytes}, $ref->{md5sum}, $ref->{type}), @$aref];
    374379
    375380            $count = $dbh->do($query, undef, @$do_args);
    376381
    377382            if ($count == 0E0) {
    378                 die("failed to insert $ref->{file} into $fileset");
     383                die("failed to insert $filename into $fileset");
    379384            }
    380385        }
Note: See TracChangeset for help on using the changeset viewer.