IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 8, 2006, 9:41:12 AM (20 years ago)
Author:
Paul Price
Message:

Fixing relative and absolute filenames.

File:
1 edited

Legend:

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

    r10566 r10568  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.14 2006-12-08 18:51:24 price Exp $
     3# $Id: Config.pm,v 1.15 2006-12-08 19:41:12 price Exp $
    44
    55package PS::IPP::Config;
     
    113113    my $scheme = $uri->scheme(); # Scheme, e.g., file, path
    114114    if (lc($scheme) eq 'file') {
    115         return File::Spec->canonpath( $uri->path() );
     115        my $host = $uri->host();
     116        my $path;
     117        if (defined $host) {
     118            # The user has file://some/directory/ but *probably* wants
     119            # /some/directory/ i.e., the URI is technically wrong
     120            # (should be one or three leading slashes, not two).  We
     121            # choose to fix it and give the user what we think they
     122            # want, rather than what they asked for.
     123            $path = File::Spec->catfile( undef, $blah, $uri->path() );
     124        } else {
     125            $path = $uri->path();
     126        }
     127
     128        return File::Spec->canonpath( $path );
    116129    }
    117130
    118131    if (lc($scheme) eq 'path') {
     132        my $authority = $uri->authority();
     133        my $path = $self->datapath( $authority );
    119134        my @segments = $uri->path_segments();
    120         my $source = shift @segments;
    121         my $path = $self->datapath( $source );
    122         my $rel = File::Spec->catfile( @segments );
    123         return File::Spec->rel2abs( $rel, $path );
     135        return File::Spec->catfile( $path, @segments );
    124136    }
    125137
     
    135147    my ($vol, $dir, $file) = File::Spec->splitpath( $name );
    136148    my @dirs = File::Spec->splitdir( $dir );
     149    pop @dirs;                  # Get rid of filename
    137150
    138151    my $path_list = _mdLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
     
    140153    my $best_name;
    141154    my $best_score;
    142   PATH_CHECK: foreach my $path_item (@$path_list) {
     155  CFR_PATH_CHECK: foreach my $path_item (@$path_list) {
    143156      my $path_name = $path_item->{name}; # Name of the path
    144       my $path = $path_item->{value}; # The path
     157      my $path = File::Spec->canonpath( $path_item->{value} ); # The path
    145158      my @path_dirs = File::Spec->splitdir( $path );
    146159
     
    148161      next if scalar @path_dirs > scalar @dirs;
    149162      for (my $i = 0; $i < scalar @path_dirs; $i++) {
    150           next PATH_CHECK if $path_dirs[$i] ne $dirs[$i];
     163          next CFR_PATH_CHECK if $path_dirs[$i] ne $dirs[$i];
    151164      }
    152165      # It is suitable; see if it is 'best' (minimizes the number of directories)
    153166      my $score = scalar @path_dirs;
    154       if ($score > $best_score) {
     167      if (not defined $best_score or $score > $best_score) {
    155168          $best_path = $path;
    156169          $best_score = $score;
     
    161174    if (defined $best_score) {
    162175        my $rel = File::Spec->abs2rel( $name, $best_path );
     176        my @segments = File::Spec->splitdir( $rel );
    163177        $uri->scheme( 'path' );
    164         $uri->path_segments( $best_name, $rel );
     178        $uri->authority( $best_name );
     179        $uri->path_segments( @segments );
    165180    } else {
    166181        $uri->scheme( 'file' );
Note: See TracChangeset for help on using the changeset viewer.