develooper Front page | perl.perl5.porters | Postings from February 2004

File::Path won't force-unlink on Win32

Thread Next
Ken Williams
February 24, 2004 13:32
File::Path won't force-unlink on Win32
Message ID:

I'm having trouble with File::Path::rmtree() on Win32 (using ActivePerl 
5.8.0, which has File::Path 1.05), as the following test shows:

  use File::Path 1.05;

  mkdir('foo', 0666) or die "Can't create foo\\: $!";
  open my($fh), '> foo\bar.txt' or die "Can't make foo\\bar.txt: $!";
  chmod(0444, 'foo\bar.txt') or die "Can't make foo\\bar.txt read-only: 
  chmod(0444, 'foo') or die "Can't make foo\\ read-only: $!";

  rmtree('foo', 1, 0);
  print "Exists? ", -e 'foo';
chmod 0666, foo/bar.txt (from 444) at C:/Perl/lib/File/ line 243.
mode = 100666 at C:/Perl/lib/File/ line 248.
unlink foo/bar.txt
Can't unlink file foo/bar.txt: Permission denied at line 8
rmdir foo
Can't remove directory foo: Directory not empty at line 8
Exists? 1

The first two output lines are from extra warn() statements I put in 
the File::Path module, to show the file's initial permission (444) and 
the permission after chmod(0666) (which is mysteriously 100666).  Both 
warnings employed sprintf("%o") to format the result of (lstat 

So the chmod(0666) thinks it's successful, but it produces a wacky 
result, and the unlink() fails afterwards.  I'm not enough of a Win32 
programmer to know what's going on here.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About