File::Spec::Unix::canonpath under cygwin

Michael A Chase mchase@ix.netcom.com
Mon May 6 14:02:00 GMT 2002


A recent exchange of email in cygwin@cygwin.com (below) indicated that
File::Spec::Unix::canonpath() has changed for Perl 5.7.3.  Part of the
change removes a Cygwin specific hack that prevented canonpath() from
combining runs of "/" into a single "/".  There was a note at that point in
the code wondering why Cygwin wanted that different processing.

The reason is the same as what caused the $node code to be added.  Cygwin
permits network path specifications that start with "//" and without the
hack, canonpath() was removing the leading "/".

Rather than putting the original Cygwin hack back in, it would be better to
add Cygwin to the list of systems that the new code applies to.

If this diff get's mangled, I can send it to whoever wants it as an
attachment.  I do not subscribe to the Perl developers' list, so please
reply directly if you need to contact me.

$ diff -up Unix.pm-orig Unix.pm
--- Unix.pm-orig        Mon Mar  4 16:10:08 2002
+++ Unix.pm     Mon May  6 13:42:52 2002
@@ -39,7 +39,7 @@ sub canonpath {

     # Handle POSIX-style node names beginning with double slash
     my $node = '';
-    if ( $^O =~ m/^(?:qnx|nto)$/ && $path =~ s:^(//[^/]+)(/|\z):/:s ) {
+    if ( $^O =~ m/^(?:qnx|nto|cygwin)$/ && $path =~ s:^(//[^/]+)(/|\z):/:s ) {
       $node = $1;
     }
     # This used to be



On Mon, 6 May 2002 17:05:56 +0200 "Gerrit P. Haase" <freeweb@nyckelpiga.de> wrote:

> Christopher schrieb:
> 
> > My question concerns the use of File::Spec->canonpath in perl (for cygwin).
> > I did a search of the relevant mailing list archives, as well as google
> > newsgroups, but did not seem to come across any hits that seem to discuss
> > this specific issue.
> 
> > As it currently stands, canonpath will not strip out multiple occurrences
> > of // in file paths when the script is executed from within a cygwin shell.
> > The relevant line from /usr/lib/perl5/5.6.1/File/Spec/Unix.pm that strips
> > out multiple /'s is
> 
> > $path =~ s|/+|/|g unless ($^O eq 'cygwin');
> 
> > I assume this regexp substitution is ignored for cygwin because we would
> > not want to munge instances where // refers to a network share (something
> > regular unix doesn't need to worry about), but is it wise to also ignore
> > all multiple forward slashes when they occur in the middle of a path?  Or
> > is this simply a non-issue because, for the most part, it seems like most
> > (if not all?)  programs don't really seem to care about multiple path
> > separators?
> 
> > For what it's worth, canonpath in ExtUtils::MM_Unix (and MM_Cygwin), uses
> 
> > $path =~ s|(?<=[^/])/+|/|g;
> 
> > which seems to do what I expect (leaves // at the front of a path alone,
> > but replaces all remaining // with /).  The only weakness I see with this
> > is that it will not replace ///shareName/path with //shareName/path, but
> > that is a minor matter, at least as it concerns me.
> 
> > Any thoughts on this matter would be most appreciated.
> 
> Perl 5.8:
> =========
> sub canonpath {
>     my ($self,$path) = @_;
>     
>     # Handle POSIX-style node names beginning with double slash
>     my $node = '';
>     if ( $^O =~ m/^(?:qnx|nto)$/ && $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
>     $path =~ s|/\Z(?!\n)|| unless $path eq "/";          # xx/       ->
> xx
>     return "$node$path";
> }
> 
> Looks more sophisticated?
> 
> 
> Gerrit

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.







--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list