Skip Menu |

This queue is for tickets about the Test-Trap CPAN distribution.

Report information
The Basics
Id: 32087
Status: resolved
Worked: 45 min
Priority: 0/
Queue: Test-Trap

People
Owner: Nobody in particular
Requestors: MSCHILLI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: v0.0.23
Fixed in: (no value)



Subject: Cleaning up temp files
This is a great module, the only thing that's missing is that it doesn't clean up after itself and leaves temp files in the /tmp directory after it's done. For example, if you run the Test::Trap test suite and check the number of files in the /tmp directory before and after, you'll see $ ls /tmp | wc -l 992 $ make test ... $ ls /tmp | wc -l 1222 By applying the attached patch, the "UNLINK => 1" option is added to all calls to tempfile() which causes File::Temp to remove the temp files when the program shuts down. Thanks for a great module! -- Mike (This bug has been reported by Kimo Rosenbaum).
Subject: test-trap-patch.txt
diff -Naur Test-Trap-v0.0.23/lib/Test/Trap/Builder/SystemSafe.pm Test-Trap-v0.0.23.patched/lib/Test/Trap/Builder/SystemSafe.pm --- Test-Trap-v0.0.23/lib/Test/Trap/Builder/SystemSafe.pm 2007-06-25 13:49:09.000000000 -0700 +++ Test-Trap-v0.0.23.patched/lib/Test/Trap/Builder/SystemSafe.pm 2008-01-04 09:12:08.360589123 -0800 @@ -17,7 +17,7 @@ if (tied *$globref or $fileno < 0) { $self->Exception("SystemSafe only works with real file descriptors; aborting"); } - my ($fh, $file) = tempfile; # XXX: Test? + my ($fh, $file) = tempfile( UNLINK => 1 ); # XXX: Test? binmode $fh; # superfluos? open my $fh_keeper, ">&$fileno" or $self->Exception("Cannot dup '$fileno' for $name: '$!'"); diff -Naur Test-Trap-v0.0.23/lib/Test/Trap/Builder/TempFile.pm Test-Trap-v0.0.23.patched/lib/Test/Trap/Builder/TempFile.pm --- Test-Trap-v0.0.23/lib/Test/Trap/Builder/TempFile.pm 2007-06-25 13:49:09.000000000 -0700 +++ Test-Trap-v0.0.23.patched/lib/Test/Trap/Builder/TempFile.pm 2008-01-04 09:08:41.871079686 -0800 @@ -14,7 +14,7 @@ my $self = shift; my ($name, $fileno, $globref) = @_; my $pid = $$; - my ($fh, $file) = tempfile; # XXX: Test? + my ($fh, $file) = tempfile( UNLINK => 1 ); # XXX: Test? binmode $fh; # superfluos? local *$globref; { diff -Naur Test-Trap-v0.0.23/t/03-files.pl Test-Trap-v0.0.23.patched/t/03-files.pl --- Test-Trap-v0.0.23/t/03-files.pl 2007-06-25 13:49:09.000000000 -0700 +++ Test-Trap-v0.0.23.patched/t/03-files.pl 2008-01-04 09:14:48.019461042 -0800 @@ -31,7 +31,7 @@ STDERR: { close STDERR; - my ($errfh, $errname) = tempfile; + my ($errfh, $errname) = tempfile( UNLINK => 1 ); open STDERR, '>', $errname; STDERR->autoflush(1); print STDOUT ''; diff -Naur Test-Trap-v0.0.23/t/06-layers.t Test-Trap-v0.0.23.patched/t/06-layers.t --- Test-Trap-v0.0.23/t/06-layers.t 2007-06-25 13:49:09.000000000 -0700 +++ Test-Trap-v0.0.23.patched/t/06-layers.t 2008-01-04 09:18:00.647639118 -0800 @@ -37,7 +37,7 @@ STDOUT: { close STDOUT; - my ($outfh, $outname) = tempfile; + my ($outfh, $outname) = tempfile( UNLINK => 1 ); open STDOUT, '>', $outname; STDOUT->autoflush(1); print STDOUT ''; @@ -46,7 +46,7 @@ STDERR: { close STDERR; - my ($errfh, $errname) = tempfile; + my ($errfh, $errname) = tempfile( UNLINK => 1 ); open STDERR, '>', $errname; STDERR->autoflush(1); print STDOUT '';
Thanks, applied! (To svn. I've been preparing a new release for a while, and as soon as it tests okay on (Linux and) Win32 and Cygwin, I'll release it. Tomorrow, most likely.) Also, duh! I've quite misread the File::Temp documentation. More precisely, I've misapplied "the temporary file is removed by the object destructor if UNLINK is set to true (the default)": While this is the case for the new method, the tempfile function has a different idea of what UNLINK should default to ... Thank you for setting me straight! Eirik, cleaning up /tmp now -- Eirik Berg Hanssen, ebhanssen@allverden.no Just this .sig then nothing more
Ah yes, it seems I forgot to close this ... This was resolved in v0.1.0 released 2008-01-14. Again, thanks! -- Eirik Berg Hanssen, ebhanssen@allverden.no Just this .sig then nothing more