# # perl-modules/Platon/File/Spec/Unix.pm # # This is hacked version of File::Spec::Unix module. # File::Spec::Unix::canonpath() didn't make cleanup # xx/yy/../zz -> xx/zz # # # Developed by Lubomir Host 'rajo' # Copyright (c) 2005 Platon SDG, http://platon.sk/ # Licensed under terms of GNU General Public License. # All rights reserved. # # Changelog: # 2005-07-19 - created # # $Platon: perl-modules/Platon/File/Spec/Unix.pm,v 1.2 2005/07/19 19:42:32 rajo Exp $ package Platon::File::Spec::Unix; use strict; use Carp; use vars qw($VERSION @ISA @EXPORT $AUTOLOAD); use base qw( File::Spec::Unix ); @ISA = qw(Exporter); @EXPORT = qw( ); $VERSION = '0.1'; sub canonpath { # {{{ my ($self, $path) = @_; # Handle POSIX-style node names beginning with double slash (qnx, nto) # Handle network path names beginning with double slash (cygwin) # (POSIX says: "a pathname that begins with two successive slashes # may be interpreted in an implementation-defined manner, although # more than two leading slashes shall be treated as a single slash.") my $node = ''; if ( $^O =~ m/^(?:qnx|nto|cygwin)$/ && $path =~ s:^(//[^/]+)(/|\z):/:s ) { $node = $1; } # This used to be # $path =~ s|/+|/|g unless($^O eq 'cygwin'); # but that made tests 29, 30, 35, 46, and 213 (as of #13272) to fail # (Mainly because trailing "" directories didn't get stripped). # Why would cygwin avoid collapsing multiple slashes into one? --jhi $path =~ s|/+|/|g; # xx////xx -> xx/xx $path =~ s@(/\.)+(/|\Z(?!\n))@/@g; # xx/././xx -> xx/xx $path =~ s|^(\./)+||s unless $path eq "./"; # ./xx -> xx $path =~ s|^/(\.\./)+|/|s; # /../../xx -> xx # added by Lubonir Host 'rajo' do { } while ($path =~ s|([^/]+)/(\.\./)||g); # xx/yy/../xx -> xx/xx $path =~ s|/\Z(?!\n)|| unless $path eq "/"; # xx/ -> xx return "$node$path"; } # }}} 1; __END__ =head1 NAME Unix - <<>> =head1 SYNOPSIS use Unix; my $xxx = new Unix; =head1 DESCRIPTION The Unix module allows you ... <<>> =head2 EXPORT <>> =head1 SEE ALSO =head1 AUTHORS Lubomir Host 'rajo', =cut # vim: ts=4 # vim600: fdm=marker fdl=0 fdc=3