IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13788


Ignore:
Timestamp:
Jun 13, 2007, 9:16:11 AM (19 years ago)
Author:
eugene
Message:

filename_absolute should prepend a /

File:
1 edited

Legend:

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

    r13724 r13788  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.59 2007-06-08 22:53:39 eugene Exp $
     3# $Id: Config.pm,v 1.60 2007-06-13 19:16:11 eugene Exp $
    44
    55package PS::IPP::Config;
     
    281281    }
    282282    if ($scheme eq 'path' or $scheme eq 'file') {
     283        # guaranteed to have a scheme (path:// or file://)
    283284        return $self->convert_filename_absolute( $name );
    284285    }
     
    304305        }
    305306        if ($scheme eq 'path' or $scheme eq 'file') {
     307            # guaranteed to have a scheme (path:// or file://)
    306308            $name = $self->convert_filename_absolute( $name );
    307309        }
     
    338340        }
    339341        if ($scheme eq 'path' or $scheme eq 'file') {
     342            # guaranteed to have a scheme (path:// or file://)
    340343            $name = $self->convert_filename_absolute( $name );
    341344        }
     
    436439
    437440    # Might need to create a directory
     441    # not guaranteed to have a scheme (path:// or file://) - might be /PATH/foobar
     442    # a relative path (PATH/foobar) is invalid here
    438443    my $resolved = $self->convert_filename_absolute( $name );
    439444    my ( $vol, $dirs, $file ) = File::Spec->splitpath( $resolved );
     
    447452
    448453# Convert a relative filename (e.g., "path://PATH/file") to an absolute (e.g., "/path/to/file")
     454# note that file://PATH/file resolves to /PATH/file, regardless of the number of leading slashes
    449455sub convert_filename_absolute
    450456{
     
    457463    }
    458464
    459     $name =~ s|/$||;
     465    $name =~ s|/$||; # drop tailing slashes (foobar/ to foobar)
    460466    my ($scheme) = $name =~ m|^(\S+):|; # The scheme, e.g., file, path
     467
     468    ## if this is already an absolute path (/PATH/file), just return the path
     469    unless (defined $scheme) {
     470        if ($name =~ m|^/|) { return $name; }
     471        # without a leading slash, this is an error
     472        carp "Programming error";
     473        exit($PS_EXIT_PROG_ERROR);
     474    }
     475
    461476    $name =~ s|^\S+:/*||;
    462     return $name if lc($scheme) eq 'file';
     477    $name = '/' . $name;
     478
     479    if (lc($scheme) eq 'file') {
     480        return $name;
     481    }
    463482
    464483    if (lc($scheme) eq 'path') {
     
    470489    }
    471490
    472     return $name;
     491    # looks like we cannot reach here without an invalid scheme. 
     492    # programming error?
     493    # return $name;
     494
     495    carp "Programming error";
     496    exit($PS_EXIT_PROG_ERROR);
    473497}
    474498
     
    490514        if ($scheme eq 'path' or $scheme eq 'file') {
    491515            # We may as well search for a 'better' path
     516            # guaranteed to have a scheme (path:// or file://)
    492517            $name = $self->convert_filename_absolute( $name );
    493518        } elsif ($scheme eq 'neb') {
Note: See TracChangeset for help on using the changeset viewer.