|
List Info
Thread: rmtree and UNC paths
|
|
| rmtree and UNC paths |
  Switzerland |
2007-02-13 12:55:58 |
|
Hello,
with the build 819 from ActivePerl I
recently received the error
Directory //phchbs-w26786/wsdisk/tmp/a
changed before chdir, aborting at ...
when I try to remove a directory tree
using an UNC path. I peeked into File::Path and saw that the routine checks
for a race condition "where a directory may be replaced by a symlink
between the initial lstat and the chdir". This fails always for UNC
paths as after doing the chdir the stat yields a device number of -1 (it
would not fail if one would start from an UNC path as the cwd but that
is probably rarely the case ... ).
This can be reproduced by the small
program below. The drive z: mounts the share //phchbs-w26786/wsdisk. Removing
the $dDir works, that of $uDir fails.
#!perl -w
use strict;
use File::Path;
use Cwd 'getcwd';
my $dDir = 'z:/tmp/a';
my $uDir = '//phchbs-w26786/wsdisk/tmp/a';
my $dir = $uDir;
my $oldpwd = getcwd or die $!;
my ($dev, $ino, $perm) = lstat $dir;
print "dev $dev, ino $ino, perm
$permn";
chdir $dir or die $!;
my ($new_dev, $new_ino) = stat '.';
print "new_dev $new_dev, new_ino
$new_inon";
chdir $oldpwd or die $!;
rmtree($dir,1,1) or die $!;
For now I found a solution by patching
my version of Path.pm in the following way:
--- Path.pm.orig
2006-01-04 08:55:28.000000000 +0100
+++ Path.pm 2007-02-13
19:10:47.534437500 +0100
 -205,8 +205,10 
# avoid a race condition
where a directory may be replaced by a
# symlink between
the initial lstat and the chdir
+ my $pathIsUNC = $path
=~ m|^[/\]| ? 1 : 0;
my ($new_dev, $new_ino)
= stat '.';
- unless ("$new_dev:$new_ino"
eq "$dev:$ino")
+ unless ( ( $new_ino ==
$ino ) &&
+
( ($new_dev == $dev) || ( ($new_dev == -1) && $pathIsUNC)
) )
{
croak "Directory
$prefix$path changed before chdir, aborting";
}
Would that be a reasonable way to account
for UNC paths? It seems to work fine.
Ekkehard
_________________________
CONFIDENTIALITY NOTICE
The information contained in this e-mail message is intended only for the
exclusive use of the individual or entity named above and may contain information
that is privileged, confidential or exempt from disclosure under applicable
law. If the reader of this message is not the intended recipient, or the
employee or agent responsible for delivery of the message to the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this communication is strictly prohibited. If you have received
this communication in error, please notify the sender immediately by e-mail
and delete the material from any computer. Thank you.
|
[1]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|