IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17970 for trunk/PS-IPP-Config


Ignore:
Timestamp:
Jun 6, 2008, 4:35:39 PM (18 years ago)
Author:
bills
Message:

have file_resolve have the same behavior in "touch" whether or not
the file is in nebulous. That is the file and (it's parent directories)
are created if they don't exist

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r17963 r17970  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.88 2008-06-06 23:46:57 bills Exp $
     3# $Id: Config.pm,v 1.89 2008-06-07 02:35:39 bills Exp $
    44
    55package PS::IPP::Config;
     
    367367    my $self = shift;                # Configuration object
    368368    my $name = shift;                # File name to check
    369     my $touch = shift;                # if $name is in nebulous instantiate it
     369    my $create_if_doesnt_exist = shift;
    370370
    371371    my $scheme = file_scheme($name); # The scheme, e.g., file://, path://
    372372
    373     return $name unless defined $scheme; # Probably a file name instead of a URI
    374     $scheme = lc($scheme);
    375 
    376     if ($scheme eq 'neb') {
    377         $self->_neb_start();
    378         my $neb = $self->{nebulous}; # Nebulous handle
    379         if ($touch) {
    380             unless ($neb->stat( $name )) {
    381                 my $uri = $neb->create( $name );
    382                 unless(defined $uri) {
    383                     carp "unable to instantiate $name.";
    384                     exit($PS_EXIT_DATA_ERROR);
     373    if ($scheme) {
     374        $scheme = lc($scheme);
     375
     376        if ($scheme eq 'neb') {
     377            $self->_neb_start();
     378            my $neb = $self->{nebulous}; # Nebulous handle
     379            if ($create_if_doesnt_exist) {
     380                unless ($neb->stat( $name )) {
     381                    my $uri = $neb->create( $name );
     382                    unless(defined $uri) {
     383                        carp "unable to instantiate $name.";
     384                        exit($PS_EXIT_DATA_ERROR);
     385                    }
     386                    my $path = URI->new( $uri )->path;
     387                    return $path;
    385388                }
    386                 my $path = URI->new( $uri )->path;
    387                 return $path;
    388389            }
    389         }
    390         return $neb->find( $name );
    391     }
    392     if ($scheme eq 'path' or $scheme eq 'file') {
    393         # guaranteed to have a scheme (path:// or file://)
    394         return $self->convert_filename_absolute( $name );
     390            return $neb->find( $name );
     391        }
     392        if ($scheme eq 'path' or $scheme eq 'file') {
     393            # guaranteed to have a scheme (path:// or file://)
     394            $name = $self->convert_filename_absolute( $name );
     395        }
     396    }
     397
     398    if ($create_if_doesnt_exist && ! -e $name) {
     399        # make sure the file's parent directory exists
     400        my $dir = dirname($name);
     401        if (! -e $dir) {
     402            my $rc = system "mkdir -p $dir";
     403            die "failed to create directory for $name" unless (!$rc);
     404        } elsif (! -d $dir ) {
     405            die "parent for $name exists and is not a directory";
     406        }
     407
     408        open F, ">$name" or die "failed to create $name";
     409        close F;
    395410    }
    396411
     
    552567    die "need name" unless $name;
    553568
    554     my $filename = $self->file_resolve($name, "--touch");
     569    my $filename = $self->file_resolve($name, 1);
    555570
    556571    die "cannot resolve $name" unless $filename;
    557 
    558     # We need to make sure the directory for this file exists
    559     # If it's a nebulous file it has already been created so the directory must exist
    560     # we won't run mkdir there
    561     my $dir = dirname($filename);
    562     if (! -d $dir) {
    563         my $rc = system "mkdir -p $dir";
    564         die "failed to create directory for $filename" unless (!$rc);
    565     }
    566572
    567573    open STDOUT, ">>$filename" or die "failed to redirect stdout to $filename";
Note: See TracChangeset for help on using the changeset viewer.