Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File::Path::remove_tree not working

91 views
Skip to first unread message

Allan Herriman

unread,
Sep 18, 2012, 4:19:32 AM9/18/12
to
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

ilovelinux

unread,
Sep 20, 2012, 2:27:55 AM9/20/12
to
> 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 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";
}
}

Allan Herriman

unread,
Sep 21, 2012, 7:44:11 AM9/21/12
to
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

ilovelinux

unread,
Sep 21, 2012, 10:18:34 AM9/21/12
to
> 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

Ben Morrow

unread,
Sep 21, 2012, 1:16:48 PM9/21/12
to

Quoth Allan Herriman <allanh...@hotmail.com>:
>
> 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.

This is usual Cygwin behaviour: in fact, it's one of the main reasons to
use Cygwin in the first place. If you don't like it, why aren't you just
using ordinary Win32 perl?

(Personally, I wouldn't touch Cygwin with a ten-foot pole.)

Ben

Kaz Kylheku

unread,
Sep 21, 2012, 3:29:10 PM9/21/12
to
On 2012-09-21, Ben Morrow <b...@morrow.me.uk> wrote:
>
> Quoth Allan Herriman <allanh...@hotmail.com>:
>>
>> 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.
>
> 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?
0 new messages