From: Gurusamy Sarathy Date: Fri, 5 May 2000 02:15:13 +0000 (+0000) Subject: File::Spec compatibility update (from Barrie Slaymaker X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9c045eb230d3b294af134ce743669059dcb2f128;p=p5sagit%2Fp5-mst-13.2.git File::Spec compatibility update (from Barrie Slaymaker ) p4raw-id: //depot/perl@6069 --- diff --git a/lib/File/Spec.pm b/lib/File/Spec.pm index 40f5345..ed26d76 100644 --- a/lib/File/Spec.pm +++ b/lib/File/Spec.pm @@ -3,7 +3,7 @@ package File::Spec; use strict; use vars qw(@ISA $VERSION); -$VERSION = '0.8'; +$VERSION = '0.81'; my %module = (MacOS => 'Mac', MSWin32 => 'Win32', diff --git a/lib/File/Spec/Mac.pm b/lib/File/Spec/Mac.pm index eeb2d81..5315d92 100644 --- a/lib/File/Spec/Mac.pm +++ b/lib/File/Spec/Mac.pm @@ -82,9 +82,9 @@ sub catdir { shift; my @args = @_; my $result = shift @args; - $result =~ s/:\z//; + $result =~ s/:\Z(?!\n)//; foreach (@args) { - s/:\z//; + s/:\Z(?!\n)//; s/^://s; $result .= ":$_"; } @@ -153,7 +153,7 @@ sub rootdir { require Mac::Files; my $system = Mac::Files::FindFolder(&Mac::Files::kOnSystemDisk, &Mac::Files::kSystemFolderType); - $system =~ s/:.*\z/:/s; + $system =~ s/:.*\Z(?!\n)/:/s; return $system; } @@ -231,7 +231,7 @@ sub splitpath { my ($volume,$directory,$file) = ('','',''); if ( $nofile ) { - ( $volume, $directory ) = $path =~ m@((?:[^:]+(?::|\z))?)(.*)@s; + ( $volume, $directory ) = $path =~ m@((?:[^:]+(?::|\Z(?!\n)))?)(.*)@s; } else { $path =~ @@ -245,8 +245,8 @@ sub splitpath { } # Make sure non-empty volumes and directories end in ':' - $volume .= ':' if $volume =~ m@[^:]\z@ ; - $directory .= ':' if $directory =~ m@[^:]\z@ ; + $volume .= ':' if $volume =~ m@[^:]\Z(?!\n)@ ; + $directory .= ':' if $directory =~ m@[^:]\Z(?!\n)@ ; return ($volume,$directory,$file); } @@ -262,7 +262,7 @@ sub splitdir { # check to be sure that there will not be any before handling the # simple case. # - if ( $directories !~ m@:\z@ ) { + if ( $directories !~ m@:\Z(?!\n)@ ) { return split( m@:@, $directories ); } else { @@ -289,11 +289,11 @@ sub catpath { my $segment ; for $segment ( @_ ) { - if ( $result =~ m@[^/]\z@ && $segment =~ m@^[^/]@s ) { + if ( $result =~ m@[^/]\Z(?!\n)@ && $segment =~ m@^[^/]@s ) { $result .= "/$segment" ; } - elsif ( $result =~ m@/\z@ && $segment =~ m@^/@s ) { - $result =~ s@/+\z@/@; + elsif ( $result =~ m@/\Z(?!\n)@ && $segment =~ m@^/@s ) { + $result =~ s@/+\Z(?!\n)@/@; $segment =~ s@^/+@@s; $result .= "$segment" ; } diff --git a/lib/File/Spec/Unix.pm b/lib/File/Spec/Unix.pm index 44cb128..6ca26d7 100644 --- a/lib/File/Spec/Unix.pm +++ b/lib/File/Spec/Unix.pm @@ -38,7 +38,7 @@ sub canonpath { $path =~ s|(/\.)+/|/|g; # xx/././xx -> xx/xx $path =~ s|^(\./)+||s unless $path eq "./"; # ./xx -> xx $path =~ s|^/(\.\./)+|/|s; # /../../xx -> xx - $path =~ s|/\z|| unless $path eq "/"; # xx/ -> xx + $path =~ s|/\Z(?!\n)|| unless $path eq "/"; # xx/ -> xx return $path; } @@ -149,7 +149,7 @@ directory. (Does not strip symlinks, only '.', '..', and equivalents.) sub no_upwards { my $self = shift; - return grep(!/^\.{1,2}\z/s, @_); + return grep(!/^\.{1,2}\Z(?!\n)/s, @_); } =item case_tolerant @@ -226,7 +226,7 @@ sub splitpath { $directory = $path; } else { - $path =~ m|^ ( (?: .* / (?: \.\.?\z )? )? ) ([^/]*) |xs; + $path =~ m|^ ( (?: .* / (?: \.\.?\Z(?!\n) )? )? ) ([^/]*) |xs; $directory = $1; $file = $2; } @@ -266,7 +266,7 @@ sub splitdir { # check to be sure that there will not be any before handling the # simple case. # - if ( $directories !~ m|/\z| ) { + if ( $directories !~ m|/\Z(?!\n)| ) { return split( m|/|, $directories ); } else { diff --git a/lib/File/Spec/VMS.pm b/lib/File/Spec/VMS.pm index 7465993..d2be87c 100644 --- a/lib/File/Spec/VMS.pm +++ b/lib/File/Spec/VMS.pm @@ -59,7 +59,7 @@ sub eliminate_macros { $complex = 1; } } - else { ($macro = unixify($self->{$macro})) =~ s#/\z##; } + else { ($macro = unixify($self->{$macro})) =~ s#/\Z(?!\n)##; } $npath = "$head$macro$tail"; } } @@ -89,8 +89,8 @@ sub fixpath { $self = bless {} unless ref $self; my($fixedpath,$prefix,$name); - if ($path =~ m#^\$\([^\)]+\)\z#s || $path =~ m#[/:>\]]#) { - if ($force_path or $path =~ /(?:DIR\)|\])\z/) { + if ($path =~ m#^\$\([^\)]+\)\Z(?!\n)#s || $path =~ m#[/:>\]]#) { + if ($force_path or $path =~ /(?:DIR\)|\])\Z(?!\n)/) { $fixedpath = vmspath($self->eliminate_macros($path)); } else { @@ -100,7 +100,7 @@ sub fixpath { elsif ((($prefix,$name) = ($path =~ m#^\$\(([^\)]+)\)(.+)#s)) && $self->{$prefix}) { my($vmspre) = $self->eliminate_macros("\$($prefix)"); # is it a dir or just a name? - $vmspre = ($vmspre =~ m|/| or $prefix =~ /DIR\z/) ? vmspath($vmspre) : ''; + $vmspre = ($vmspre =~ m|/| or $prefix =~ /DIR\Z(?!\n)/) ? vmspath($vmspre) : ''; $fixedpath = ($vmspre ? $vmspre : $self->{$prefix}) . $name; $fixedpath = vmspath($fixedpath) if $force_path; } @@ -139,7 +139,7 @@ sub canonpath { my($self,$path) = @_; if ($path =~ m|/|) { # Fake Unix - my $pathify = $path =~ m|/\z|; + my $pathify = $path =~ m|/\Z(?!\n)|; $path = $self->SUPER::canonpath($path); if ($pathify) { return vmspath($path); } else { return vmsify($path); } @@ -172,8 +172,8 @@ sub catdir { if (@dirs) { my $path = (@dirs == 1 ? $dirs[0] : $self->catdir(@dirs)); my ($spath,$sdir) = ($path,$dir); - $spath =~ s/\.dir\z//; $sdir =~ s/\.dir\z//; - $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+\z/s; + $spath =~ s/\.dir\Z(?!\n)//; $sdir =~ s/\.dir\Z(?!\n)//; + $sdir = $self->eliminate_macros($sdir) unless $sdir =~ /^[\w\-]+\Z(?!\n)/s; $rslt = $self->fixpath($self->eliminate_macros($spath)."/$sdir",1); # Special case for VMS absolute directory specs: these will have had device @@ -184,7 +184,7 @@ sub catdir { } else { if (not defined $dir or not length $dir) { $rslt = ''; } - elsif ($dir =~ /^\$\([^\)]+\)\z/s) { $rslt = $dir; } + elsif ($dir =~ /^\$\([^\)]+\)\Z(?!\n)/s) { $rslt = $dir; } else { $rslt = vmspath($dir); } } return $self->canonpath($rslt); @@ -205,8 +205,8 @@ sub catfile { if (@files) { my $path = (@files == 1 ? $files[0] : $self->catdir(@files)); my $spath = $path; - $spath =~ s/\.dir\z//; - if ($spath =~ /^[^\)\]\/:>]+\)\z/s && basename($file) eq $file) { + $spath =~ s/\.dir\Z(?!\n)//; + if ($spath =~ /^[^\)\]\/:>]+\)\Z(?!\n)/s && basename($file) eq $file) { $rslt = "$spath$file"; } else { @@ -313,7 +313,7 @@ Checks for VMS directory spec as well as Unix separators. sub file_name_is_absolute { my ($self,$file) = @_; # If it's a logical name, expand it. - $file = $ENV{$file} while $file =~ /^[\w\$\-]+\z/s && $ENV{$file}; + $file = $ENV{$file} while $file =~ /^[\w\$\-]+\Z(?!\n)/s && $ENV{$file}; return scalar($file =~ m!^/!s || $file =~ m![<\[][^.\-\]>]! || $file =~ /:[^<\[]/); @@ -344,7 +344,7 @@ sub splitdir { $dirspec =~ s/\]\[//g; $dirspec =~ s/\-\-/-.-/g; $dirspec = "[$dirspec]" unless $dirspec =~ /[\[<]/; # make legal my(@dirs) = split('\.', vmspath($dirspec)); - $dirs[0] =~ s/^[\[<]//s; $dirs[-1] =~ s/[\]>]\z//s; + $dirs[0] =~ s/^[\[<]//s; $dirs[-1] =~ s/[\]>]\Z(?!\n)//s; @dirs; } @@ -358,7 +358,7 @@ Construct a complete filespec using VMS syntax sub catpath { my($self,$dev,$dir,$file) = @_; if ($dev =~ m|^/+([^/]+)|) { $dev = "$1:"; } - else { $dev .= ':' unless $dev eq '' or $dev =~ /:\z/; } + else { $dev .= ':' unless $dev eq '' or $dev =~ /:\Z(?!\n)/; } if (length($dev) or length($dir)) { $dir = "[$dir]" unless $dir =~ /[\[<\/]/; $dir = vmspath($dir); @@ -403,17 +403,16 @@ sub abs2rel { } # Split up paths - my ( undef, $path_directories, $path_file ) = - $self->splitpath( $path, 1 ) ; + my ( $path_directories, $path_file ) = + ($self->splitpath( $path, 1 ))[1,2] ; $path_directories = $1 - if $path_directories =~ /^\[(.*)\]\z/s ; + if $path_directories =~ /^\[(.*)\]\Z(?!\n)/s ; - my ( undef, $base_directories, undef ) = - $self->splitpath( $base, 1 ) ; + my $base_directories = ($self->splitpath( $base, 1 ))[1] ; $base_directories = $1 - if $base_directories =~ /^\[(.*)\]\z/s ; + if $base_directories =~ /^\[(.*)\]\Z(?!\n)/s ; # Now, remove all leading components that are the same my @pathchunks = $self->splitdir( $path_directories ); @@ -430,7 +429,7 @@ sub abs2rel { # @basechunks now contains the directories to climb out of, # @pathchunks now has the directories to descend in to. $path_directories = '-.' x @basechunks . join( '.', @pathchunks ) ; - $path_directories =~ s{\.\z}{} ; + $path_directories =~ s{\.\Z(?!\n)}{} ; return $self->canonpath( $self->catpath( '', $path_directories, $path_file ) ) ; } @@ -461,17 +460,17 @@ sub rel2abs($;$;) { } # Split up paths - my ( undef, $path_directories, $path_file ) = - $self->splitpath( $path ) ; + my ( $path_directories, $path_file ) = + ($self->splitpath( $path ))[1,2] ; - my ( $base_volume, $base_directories, undef ) = + my ( $base_volume, $base_directories ) = $self->splitpath( $base ) ; $path_directories = '' if $path_directories eq '[]' || $path_directories eq '<>'; my $sep = '' ; $sep = '.' - if ( $base_directories =~ m{[^.\]>]\z} && + if ( $base_directories =~ m{[^.\]>]\Z(?!\n)} && $path_directories =~ m{^[^.\[<]}s ) ; $base_directories = "$base_directories$sep$path_directories"; diff --git a/lib/File/Spec/Win32.pm b/lib/File/Spec/Win32.pm index fb39269..b8fe37b 100644 --- a/lib/File/Spec/Win32.pm +++ b/lib/File/Spec/Win32.pm @@ -108,8 +108,8 @@ sub canonpath { $path =~ s|([^\\])\\+|$1\\|g; # xx////xx -> xx/xx $path =~ s|(\\\.)+\\|\\|g; # xx/././xx -> xx/xx $path =~ s|^(\.\\)+||s unless $path eq ".\\"; # ./xx -> xx - $path =~ s|\\\z|| - unless $path =~ m#^([A-Z]:)?\\\z#s; # xx/ -> xx + $path =~ s|\\\Z(?!\n)|| + unless $path =~ m#^([A-Z]:)?\\\Z(?!\n)#s; # xx/ -> xx return $path; } @@ -149,7 +149,7 @@ sub splitpath { (?:\\\\|//)[^\\/]+[\\/][^\\/]+ )? ) - ( (?:.*[\\\\/](?:\.\.?\z)?)? ) + ( (?:.*[\\\\/](?:\.\.?\Z(?!\n))?)? ) (.*) }xs; $volume = $1; @@ -190,7 +190,7 @@ sub splitdir { # check to be sure that there will not be any before handling the # simple case. # - if ( $directories !~ m|[\\/]\z| ) { + if ( $directories !~ m|[\\/]\Z(?!\n)| ) { return split( m|[\\/]|, $directories ); } else { @@ -219,7 +219,7 @@ sub catpath { # If it's UNC, make sure the glue separator is there, reusing # whatever separator is first in the $volume $volume .= $1 - if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\z@s && + if ( $volume =~ m@^([\\/])[\\/][^\\/]+[\\/][^\\/]+\Z(?!\n)@s && $directory =~ m@^[^\\/]@s ) ; @@ -227,8 +227,8 @@ sub catpath { # If the volume is not just A:, make sure the glue separator is # there, reusing whatever separator is first in the $volume if possible. - if ( $volume !~ m@^[a-zA-Z]:\z@s && - $volume =~ m@[^\\/]\z@ && + if ( $volume !~ m@^[a-zA-Z]:\Z(?!\n)@s && + $volume =~ m@[^\\/]\Z(?!\n)@ && $file =~ m@[^\\/]@ ) { $volume =~ m@([\\/])@ ; @@ -296,8 +296,7 @@ sub abs2rel { my ( $path_volume, $path_directories, $path_file ) = $self->splitpath( $path, 1 ) ; - my ( undef, $base_directories, undef ) = - $self->splitpath( $base, 1 ) ; + my $base_directories = ($self->splitpath( $base, 1 ))[1] ; # Now, remove all leading components that are the same my @pathchunks = $self->splitdir( $path_directories ); @@ -381,10 +380,10 @@ sub rel2abs($;$;) { $base = $self->canonpath( $base ) ; } - my ( undef, $path_directories, $path_file ) = - $self->splitpath( $path, 1 ) ; + my ( $path_directories, $path_file ) = + ($self->splitpath( $path, 1 ))[1,2] ; - my ( $base_volume, $base_directories, undef ) = + my ( $base_volume, $base_directories ) = $self->splitpath( $base, 1 ) ; $path = $self->catpath(