IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16342


Ignore:
Timestamp:
Feb 6, 2008, 1:48:13 PM (18 years ago)
Author:
eugene
Message:

use local file for tmpfile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStore/scripts/dsget

    r16301 r16342  
    33# Copyright (C) 2006-2008  Joshua Hoblitt
    44#
    5 # $Id: dsget,v 1.12 2008-02-05 04:57:10 eugene Exp $
     5# $Id: dsget,v 1.13 2008-02-06 23:48:13 eugene Exp $
    66
    77use strict;
     
    5151}
    5252
    53 # if ($uriVolume) {
    54 #     print "uriVolume: $uriVolume\n";
    55 # }
    56 # if ($uriFilename) {
    57 #     print "uriFilename: $uriFilename\n";
    58 # }
    59 
    6053if ($volume and $uriVolume and ($volume ne $uriVolume)) {
    6154    die "conflicting volume names specified";
     
    6558if ($uriFilename) { $filename = $uriFilename; }
    6659
    67 # if ($volume) {
    68 #     print "volume: $volume\n";
    69 # } else {
    70 #     print "volume undefined\n";
    71 # }
    72 # print "filename: $filename\n";
    73 # if ($nebulous) {
    74 #     print "using nebulous\n";
    75 # }
     60# XXX EAM : should not need parse_neb_key, but how to handle case
     61# where we supply --volume and neb://volume/path ?
     62# 1) parse anyway and check for conflict
     63# 2) drop --volume option
    7664
    7765my %p = (
     
    8371$p{md5sum} = $md5 if defined $md5;
    8472
    85 my $dirname = dirname($filename);
    86 
    87 if (!-d $dirname) {
     73my $tmp;
     74
     75if (!$nebulous) {
     76
    8877    # create path and possibly fix up permissions
    89     mkpath([$dirname], 1, 0775);
    90 }
    91 
    92 # can we truely write to filename?
    93 {
    94     # open file for read/write but not create
    95     my $fh;
    96     if (open($fh, '+<', $filename)) {
    97         # do nothing and fall through
    98     } elsif (open($fh, '>>', $filename)) {
    99         # this is the "stomp on it behavior" this probably shouldn't be the
    100         # default and it may make sense to check the md5sum/bytes count of the
    101         # files that's already in place to see if we really need to re-fetch it
    102         unlink $filename or die "can't unlink $filename: $!";
    103     } else {
    104         die "can't write to $filename";
     78    my $dirname = dirname($filename);
     79    if (!-d $dirname) {
     80        mkpath([$dirname], 1, 0775);
    10581    }
    106 }
    107 
    108 my $tmp = File::Temp->new(
    109     DIR         => $dirname,
    110     TEMPLATE    => '.' . basename($filename) . '.XXXXXXXX',
    111     SUFFIX      => '.tmp',
    112     UNLINK      => 1,
    113 );
     82
     83    # can we truly write to filename?
     84    {
     85        # open file for read/write but not create
     86        my $fh;
     87        if (open($fh, '+<', $filename)) {
     88            # do nothing and fall through
     89        } elsif (open($fh, '>>', $filename)) {
     90            # this is the "stomp on it behavior" this probably shouldn't be the
     91            # default and it may make sense to check the md5sum/bytes count of the
     92            # files that's already in place to see if we really need to re-fetch it
     93            unlink $filename or die "can't unlink $filename: $!";
     94        } else {
     95            die "can't write to $filename";
     96        }
     97    }
     98
     99    # for non-neb files, use the download directory for the tmp file
     100    $tmp = File::Temp->new(
     101                           DIR         => $dirname,
     102                           TEMPLATE    => '.' . basename($filename) . '.XXXXXXXX',
     103                           SUFFIX      => '.tmp',
     104                           UNLINK      => 1,
     105                           );
     106} else {
     107    # for neb files, use /tmp for the tmp file
     108    $tmp = File::Temp->new(
     109                           DIR         => '/tmp',
     110                           TEMPLATE    => basename($filename) . '.XXXXXXXX',
     111                           SUFFIX      => '.tmp',
     112                           UNLINK      => 1,
     113                           );
     114}
    114115
    115116my $tmpfilename = $tmp->filename;
    116 
     117print "downloading file to $tmpfilename\n";
     118
     119# request the file from the remote data store server (save in tmpfilename)
    117120my $response = DataStore::File->new(%p)->request( filename => $tmpfilename );
    118121
Note: See TracChangeset for help on using the changeset viewer.