Skip Menu |

This queue is for tickets about the Cwd CPAN distribution.

Report information
The Basics
Id: 6146
Status: resolved
Priority: 0/
Queue: Cwd

People
Owner: Nobody in particular
Requestors: stefan.scherer [...] sealsystems.de
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.17
Fixed in: 2.18



Subject: Cwd is very slow on MSWin32
I found out that the Cwd.pm takes very long to load on my Windows XP machine. I've tried ActivePerl 5.8.0, but also updated to Cwd 2.17. The reason is that the Cwd.pm searches for the pwd command in the whole PATH, which shouldn't be done for windows. My path contains also network drives which take long to look at. The following code snipped is my workaround in Cwd.pm, perhaps you find a much better solution to avoid the PATH lookup for windows. ===line 218============================================ # Since some ports may predefine cwd internally (e.g., NT) # we take care not to override an existing definition for cwd(). unless(defined &cwd) { # The pwd command is not available in some chroot(2)'ed environments ## SS don't look into path on windows ## if( $^O eq 'MacOS' || (defined $ENV{PATH} && ## grep { -x "$_/pwd" } split(':', $ENV{PATH})) ) ## { ## *cwd = \&_backtick_pwd; ## } ## else { *cwd = \&getcwd; ## } } ======================================================
If your network drives are in the format //volume/mount/..., then the following patch should help. Can you confirm? diff -u -r1.21 Cwd.pm --- Cwd.pm 2004/03/10 13:56:29 1.21 +++ Cwd.pm 2004/04/29 04:21:37 @@ -215,13 +215,21 @@ $cwd; } +sub _local_paths { + return unless defined $ENV{PATH}; + my @path = split ':', $ENV{PATH}; + + # Remove some obvious non-local paths + @path = grep !m{^//}, @path if $^O eq 'MSWin32'; + return @path; +} + # Since some ports may predefine cwd internally (e.g., NT) # we take care not to override an existing definition for cwd(). unless(defined &cwd) { # The pwd command is not available in some chroot(2)'ed environments - if( $^O eq 'MacOS' || (defined $ENV{PATH} && - grep { -x "$_/pwd" } split(':', $ENV{PATH})) ) + if( $^O eq 'MacOS' || grep { -x "$_/pwd" } _local_paths() ) { *cwd = \&_backtick_pwd; }
Some notes to Windows: The PATH is separated with ";" instead of ":" and windows does NOT have a pwd command (no pwd.exe). In the Cwd.pm I see a call to Win32::GetCwd() which works fine for perl 5.005 and Active Perl 5.8.1. This function returns the current dir without the need of searching for a pwd command. So a patch to Cwd.pm should more look like if( $^O eq 'MSWin32') { *cwd = \&_NT_cwd; } else { unless(defined &cwd) { # The pwd command is not available in some chroot(2)'ed environments if( $^O eq 'MacOS' || (defined $ENV{PATH} && grep { -x "$_/pwd" } split(':', $ENV{PATH})) ) { *cwd = \&_backtick_pwd; } ... At the end of Cwd.pm there is a long if-else construct which sets _NT_cwd() for some functions for Windows, but the current Cwd.pm doesn't runs through this code on windows. The split(':', $ENV{PATH}) should only be done for platforms that have a pwd command, eg. Unix. I hope that helps you a little bit.