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

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

Thread Next
From:
Ken Williams
Date:
February 24, 2004 13:32
Subject:
File::Path won't force-unlink on Win32
Message ID:
EF3296EE-6710-11D8-A5B6-003065F6D85A@mathforum.org
Hi,

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/Path.pm line 243.
mode = 100666 at C:/Perl/lib/File/Path.pm line 248.
unlink foo/bar.txt
Can't unlink file foo/bar.txt: Permission denied at file-path.pl line 8
rmdir foo
Can't remove directory foo: Directory not empty at file-path.pl 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 
$root)[2].

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.

  -Ken


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About