From: Olivier Mengué Date: Sun, 17 Feb 2013 07:06:36 +0000 (+0100) Subject: Move Win32 magic out of ensure_dir_structure_for() X-Git-Tag: 1.008008~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2Flocal-lib.git;a=commitdiff_plain;h=c1ed5f4bf162501712d308bde66c8cb1d162ddc2 Move Win32 magic out of ensure_dir_structure_for() Note that this magic has never been documented in the POD. t/stackable.t is fixed accordingly as it used the magic. --- diff --git a/lib/local/lib.pm b/lib/local/lib.pm index 5a6d9ab..a97a78f 100644 --- a/lib/local/lib.pm +++ b/lib/local/lib.pm @@ -207,7 +207,13 @@ sub setup_local_lib_for { my $interpolate = LITERAL_ENV; my @active_lls = $class->active_paths; - $path = $class->ensure_dir_structure_for($path); + $class->ensure_dir_structure_for($path); + + # On Win32 directories often contain spaces. But some parts of the CPAN + # toolchain don't like that. To avoid this, GetShortPathName() gives us + # an alternate representation that has none. + # This only works if the directory already exists. + $path = Win32::GetShortPathName($path) if $^O eq 'MSWin32'; if (! $deactivating) { if (@active_lls && $active_lls[-1] eq $path) { @@ -253,11 +259,7 @@ sub ensure_dir_structure_for { warn "Attempting to create directory ${path}\n"; } File::Path::mkpath($path); - # Need to have the path exist to make a short name for it, so - # converting to a short name here. - $path = Win32::GetShortPathName($path) if $^O eq 'MSWin32'; - - return $path; + return } sub guess_shelltype { diff --git a/t/stackable.t b/t/stackable.t index 973e4f7..6029a3a 100644 --- a/t/stackable.t +++ b/t/stackable.t @@ -8,11 +8,23 @@ plan tests => 19; use local::lib (); -my $dir1 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1); -$dir1 = local::lib->ensure_dir_structure_for($dir1); - -my $dir2 = tempdir('test_local_lib-XXXXX', DIR => Cwd::abs_path('t'), CLEANUP => 1); -$dir2 = local::lib->ensure_dir_structure_for($dir2); +sub mk_temp_dir +{ + my $name_template = shift; + + my $path = tempdir($name_template, DIR => Cwd::abs_path('t'), CLEANUP => 1); + local::lib->ensure_dir_structure_for($path); + # On Win32 the path where the distribution is built usually contains + # spaces. This is a problem for some parts of the CPAN toolchain, so + # local::lib uses the GetShortPathName trick do get an alternate + # representation of the path that doesn't constain spaces. + return ($^O eq 'MSWin32') + ? Win32::GetShortPathName($path) + : $path +} + +my $dir1 = mk_temp_dir('test_local_lib-XXXXX'); +my $dir2 = mk_temp_dir('test_local_lib-XXXXX'); my $prev_active = () = local::lib->active_paths;