Bug#619550: File::Temp CLEANUP + chdir gotcha still remains

Dominic Hargreaves dom at earth.li
Sun Apr 17 13:34:00 UTC 2011


forwarded 619550 https://rt.cpan.org/Public/Bug/Display.html?id=45246
tags 619550 + patch
thanks

On Thu, Apr 14, 2011 at 11:44:36AM +0100, Dominic Hargreaves wrote:
> On Thu, Mar 24, 2011 at 08:23:53PM -0400, Joey Hess wrote:
> > Bug #479317 explains a gotcha with use of File::Temp::tempdir(CLEANUP => 1).
> > If the code chdirs into the temp dir, which is a common thing to do,
> > and then exits without chdiring out, which is not an uncommon thing,
> > the cleanup code will fail to run.
> > 
> > The bug was closed because it was at least made not to crash the
> > program. However, this gotcha still remains. A program that has
> > combined these two common things will be subject to emitting strange
> > error messages:
> > 
> > cannot remove path when cwd is /home/e-test/tmp/cQei_Q1aVi
> > 
> > .. and leaving behind temp dirs.
> > 
> > I now have at least 3 programs that work around this problem by
> > 
> > END {
> > 	chdir("/)";
> > }
> > 
> > It's very annoying to have to remember this bug and add this to my code
> > every time I pull File::Temp into a program.
> 
> Hi Joey,
> 
> Thanks for taking the time to point out that this still isn't perfect.
> 
> I wonder whether it would be feasible to simply add the relevant
> chdir("/") (or presumably the more OS-portable equivalents) into
> File::Temp itself. Adding this at the start of the cleanup routine
> of 0.22 seems to DTRT.

Aha, someone else has already filed this as a bug with a patch:
<https://rt.cpan.org/Public/Bug/Display.html?id=45246>

Dominic.

-- 
Dominic Hargreaves | http://www.larted.org.uk/~dom/
PGP key 5178E2A5 from the.earth.li (keyserver,web,email)






More information about the Perl-maintainers mailing list