IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17450


Ignore:
Timestamp:
Apr 17, 2008, 2:35:35 PM (18 years ago)
Author:
jhoblitt
Message:

change dsget to overwrite existing Nebulous keys

Location:
trunk/DataStore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStore/Changes

    r11834 r17450  
    22
    330.07
     4    - change dsget to overwrite existing Nebulous keys
    45    - trap exceptions from DateStore::File::Parse in DataStore::FileSet being
    56      caused by empty file lists
  • trunk/DataStore/scripts/dsget

    r16368 r17450  
    33# Copyright (C) 2006-2008  Joshua Hoblitt
    44#
    5 # $Id: dsget,v 1.14 2008-02-08 19:30:38 eugene Exp $
     5# $Id: dsget,v 1.15 2008-04-18 00:35:35 jhoblitt Exp $
    66
    77use strict;
     
    8383    my $dirname = dirname($filename);
    8484    if (!-d $dirname) {
    85         mkpath([$dirname], 1, 0775);
     85        mkpath([$dirname], 1, 0775);
    8686    }
    8787
    8888    # can we truly write to filename?
    89     {
    90         # open file for read/write but not create
    91         my $fh;
    92         if (open($fh, '+<', $filename)) {
    93             # do nothing and fall through
    94         } elsif (open($fh, '>>', $filename)) {
    95             # this is the "stomp on it behavior" this probably shouldn't be the
    96             # default and it may make sense to check the md5sum/bytes count of the
    97             # files that's already in place to see if we really need to re-fetch it
    98             unlink $filename or die "can't unlink $filename: $!";
    99         } else {
    100             die "can't write to $filename";
    101         }
     89{
     90    # open file for read/write but not create
     91    my $fh;
     92    if (open($fh, '+<', $filename)) {
     93        # do nothing and fall through
     94    } elsif (open($fh, '>>', $filename)) {
     95        # this is the "stomp on it behavior" this probably shouldn't be the
     96        # default and it may make sense to check the md5sum/bytes count of the
     97        # files that's already in place to see if we really need to re-fetch it
     98        unlink $filename or die "can't unlink $filename: $!";
     99    } else {
     100        die "can't write to $filename";
    102101    }
     102}
    103103
    104104    # for non-neb files, use the download directory for the tmp file
    105105    $tmp = File::Temp->new(
    106                            DIR         => $dirname,
    107                            TEMPLATE    => '.' . basename($filename) . '.XXXXXXXX',
    108                            SUFFIX      => '.tmp',
    109                            UNLINK      => 1,
    110                            );
     106               DIR         => $dirname,
     107               TEMPLATE    => '.' . basename($filename) . '.XXXXXXXX',
     108               SUFFIX      => '.tmp',
     109               UNLINK      => 1,
     110               );
    111111} else {
    112112    # for neb files, use /tmp for the tmp file
    113113    $tmp = File::Temp->new(
    114                            DIR         => '/tmp',
    115                            TEMPLATE    => basename($filename) . '.XXXXXXXX',
    116                            SUFFIX      => '.tmp',
    117                            UNLINK      => 1,
    118                            );
     114               DIR         => '/tmp',
     115               TEMPLATE    => basename($filename) . '.XXXXXXXX',
     116               SUFFIX      => '.tmp',
     117               UNLINK      => 1,
     118               );
    119119}
    120120
     
    144144        unless defined $neb;
    145145
     146    # XXX see comment above and not blindly stomping
     147    # if the key doesn't already exist then create it
     148    # if it does, delete it so that we end up on the right storage volume
     149    if ($neb->stat($filename)) {
     150        $neb->delete($filename)
     151            or die "Nebulous can't delete key $filename";
     152    }
     153
    146154    my $fh = $neb->open_create( $filename, $volume )
    147155        or die "Nebulous can't create key $filename";
     156
    148157    open(my $src_fh, $tmpfilename) or die "can't open file $tmpfilename: $!";
    149158
Note: See TracChangeset for help on using the changeset viewer.