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 '';