Subject: | pathmk breaks if called with an UNC path |
File::Copy::Recursive::pathmk does not work if it is called on Windows
with an UNC path as argument. The reason for the bug is in the first
line in function pathmk, which reads like this:
my @parts = File::Spec->splitdir( shift() );
According to the perldoc of splitdir, the argument must NOT contain a
volume information (which on Windows means: No drive letter, no UNC
share). Despite this restriction, it just happens to work by accident,
if there *IS* a drive letter, but it fails if it is an UNC path.
SOLUTION:
To solve this, it is necessary to first extract the volume part:
my ($volume, $dir) = File::Spec->splitpath(shift());
On Unix, $volume would be ''. On Windows, $volume would be something
like 'D:' or '\\\\hostxy\\myshare'.
Next, we can use splitdir safely:
my @parts = File::Spec->splitdir($dir);
But we have to prepend the volume later, so instead of
my $pth = $parts[0];
we have to write
my $pth = File::Spec->catdir($volume,$parts[0]);
which works on both Windows and Unix.