Subject: | cleanup fails if chdired into subdir of temp dir |
Hi,
as described in <http://bugs.debian.org/479317>, upgrading to Perl
5.10.0 revealed an incompatibility in File::Temp and File::Path::rmtree
interaction that results in cleanup failure when the user has chdir()'d
into the temporary directory.
# perl -e 'use File::Temp; my $t=File::Temp::tempdir(TMPDIR => 1,
CLEANUP => 1); mkdir("$t/foo"); chdir "$t/foo"; print "now exiting\n"'
now exiting
cannot chdir to /tmp/4KqKcPWwn_/foo from /tmp/4KqKcPWwn_: No such file
or directory, aborting. at /usr/share/perl5/File/Temp.pm line 901
Joey Hess writes: "At exit, File::Temp calls rmtree to delete the temp
directory. After deleting the directory, rmtree tries to chdir back to
that location so as to not "leave the client code in an unexpected
directory". But it's deleted the directory, so of course this fails!"
I have reproduced this with File::Temp 0.20 and File::Path 2.04.
IMO, both File::Temp and File::Path::rmtree are doing mostly the right
thing here, it's a bit hard to say what should be fixed. The paranoia in
rmtree() isn't unfounded at all, there have been several CVEs in the
past due to race conditions and the like.
As I see it, File::Temp could either call rmtree in an eval block and
try to catch this particular error (figuring out the reason for the
error might be non-trivial, though) or just document the issue and leave
it at that. Please consider at least the latter option.
Many thanks for your work on File::Temp,
--
Niko Tyni
ntyni@debian.org