File::Path::remove_tree not working

A

Allan Herriman

Hi,

I have a script that creates a temporary directory using

my $tempdir = tempdir( CLEANUP => 1 );

Some readonly files are then created in that directory. All are closed
before the script finishes.

On my development machine (Activestate Perl 5.16.0 on Windows 7) it
worked fine: the directory was removed after the script finished.

On the deployment machines (Cygwin Perl 5.10.1 on Windows Server 2003) it
doesn't remove the directory or any of the files in the directory.



I then added the following line at the end of the script:

remove_tree($tempdir, { safe => 0 });

but that didn't fix anything.

It didn't write anything to STDERR, which I think indicates it didn't
encounter detectable error conditions.

I'm using -w and strict.

I can manually delete the directory in windows explorer without any
warnings or prompts, so it doesn't appear to be a permission problem.


What do I do next?


Thanks,
Allan
 
I

ilovelinux

my $tempdir = tempdir( CLEANUP => 1 );
remove_tree($tempdir, { safe => 0 });

Smells like somethnig weird in the Cygwin layer. I once encountered a similar error: the Cygwin perl script removed some files but they stayed visiblefrom an Explorer view in another window, until the perl script finished: only then the removed files disappeared.

Did you try removing the files by hand-crafted code? Something like this:

for (glob("$tempdir/*")) {
print "removing $_: ";
if (unlink($_)) {
print "OK\n";
} else {
print "ERR ($!)\n";
}
}
 
A

Allan Herriman

Smells like somethnig weird in the Cygwin layer. I once encountered a
similar error: the Cygwin perl script removed some files but they stayed
visible from an Explorer view in another window, until the perl script
finished: only then the removed files disappeared.

Did you try removing the files by hand-crafted code? Something like
this:

for (glob("$tempdir/*")) {
print "removing $_: ";
if (unlink($_)) {
print "OK\n";
} else {
print "ERR ($!)\n";
}
}


I even tried rm -rf and that didn't work, which I found rather surprising.
Smells like somethnig weird in the Cygwin layer.

It turns out that in Cygwin paths starting with /tmp/ get magically
redirected to c:/cygwin/tmp/
I cannot imagine a universe where that would be a good idea, but
apparently the Cygwin authors thought it was.

tempdir returns /tmp/something, and this gets interpreted as
c:/tmp/something by some parts of my script and as
c:/cygwin/tmp/something by other parts of my script (including tempdir
itself).

tempdir does in fact clean up its directory, but not the directory I
thought it was using.

My ugly, non-portable and fragile workaround is to chdir to c: then
prepend the temp directory name with c: before I use it.

Regards,
Allan
 
I

ilovelinux

It turns out that in Cygwin paths starting with /tmp/ get magically
redirected to c:/cygwin/tmp/

Not if you mount it yourself. My /etc/fstab (Cygwin) contains

c:/temp /tmp some_fs binary 0 0
d:/Users /home some_fs binary 0 0
none / cygdrive binary,posix=0,user 0 0

The top line forces all accesses of /tmp to use the c:/temp directory.

HTH
 
K

Kaz Kylheku

This is usual Cygwin behaviour: in fact, it's one of the main reasons to
use Cygwin in the first place.

One of the main reasons for using Cygwin is where it sticks /tmp?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top