remove volume from result
Barrie Slaymaker [Mon, 12 Nov 2001 11:19:52 +0000 (06:19 -0500)]
Message-ID: <20011112111948.C7626@sizzle.whoville.com>

p4raw-id: //depot/perl@12957

lib/File/Spec.t
lib/File/Spec/Win32.pm

index 71a0b7a..306a131 100755 (executable)
@@ -196,6 +196,9 @@ if ($^O eq 'MacOS') {
 [ "Win32->canonpath('//a/b/../../c')",  '\\\\a\\b\\..\\..\\c' ],
 [ "Win32->canonpath('//a/../../c')",    '\\\\a\\..\\..\\c'    ],
 
+## Hmmm, we should test missing and relative base paths some day...
+## would need to cd to a known place, get the cwd() and use it I
+## think.
 [  "Win32->abs2rel('/t1/t2/t3','/t1/t2/t3')",    ''                       ],
 [  "Win32->abs2rel('/t1/t2/t4','/t1/t2/t3')",    '..\\t4'                 ],
 [  "Win32->abs2rel('/t1/t2','/t1/t2/t3')",       '..'                     ],
@@ -208,6 +211,8 @@ if ($^O eq 'MacOS') {
 [  "Win32->abs2rel('/./','/t1/t2/t3')",          '..\\..\\..'             ],
 [  "Win32->abs2rel('\\\\a/t1/t2/t4','/t2/t3')",  '..\\t4'                 ],
 [  "Win32->abs2rel('//a/t1/t2/t4','/t2/t3')",    '..\\t4'                 ],
+[  "Win32->abs2rel('A:/t1/t2/t3','B:/t1/t2/t3')",''                       ],
+[  "Win32->abs2rel('A:/t1/t2/t3/t4','B:/t1/t2/t3')",'t4'                  ],
 
 [ "Win32->rel2abs('temp','C:/')",                       'C:\\temp'                        ],
 [ "Win32->rel2abs('temp','C:/a')",                      'C:\\a\\temp'                     ],
index d2e94bc..ceebb2d 100644 (file)
@@ -277,7 +277,7 @@ sub abs2rel {
     }
 
     # Split up paths
-    my ( $path_volume, $path_directories, $path_file ) =
+    my ( undef, $path_directories, $path_file ) =
         $self->splitpath( $path, 1 ) ;
 
     my $base_directories = ($self->splitpath( $base, 1 ))[1] ;
@@ -315,11 +315,8 @@ sub abs2rel {
         $path_directories = "$base_directories$path_directories" ;
     }
 
-    # It makes no sense to add a relative path to a UNC volume
-    $path_volume = '' unless $path_volume =~ m{^[A-Z]:}is ;
-
     return $self->canonpath( 
-        $self->catpath($path_volume, $path_directories, $path_file ) 
+        $self->catpath( "", $path_directories, $path_file ) 
     ) ;
 }