From 7299ca586a6a78a40081a6e7e2e94c3b1a8aa538 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 7 Jan 2010 14:22:39 +0000 Subject: Unlink PerlIO's tempfiles for the case of no -T, but bogus $ENV{TMPDIR} When -T is enabled, or when $ENV{TMPDIR} is bogus, perlio.c used a pathname matching . However, it was only correctly unlinking the file for the case of -T enabled. --- t/io/perlio.t | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 't') diff --git a/t/io/perlio.t b/t/io/perlio.t index 1499ca2802..3a81512c82 100644 --- a/t/io/perlio.t +++ b/t/io/perlio.t @@ -9,7 +9,7 @@ BEGIN { require './test.pl'; } -plan tests => 40; +plan tests => 42; use_ok('PerlIO'); @@ -97,16 +97,36 @@ ok(close($utffh)); if !$Config{d_mkstemp} || $^O eq 'VMS' || $^O eq 'MSwin32' || $^O eq 'os2'; local $ENV{TMPDIR} = $nonexistent; + + # hardcoded default temp path + my $perlio_tmp_file_glob = '/tmp/PerlIO_??????'; + + my @before = glob $perlio_tmp_file_glob; + ok( open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - works if TMPDIR points to a non-existent dir'); + my @after = glob $perlio_tmp_file_glob; + is( "@after", "@before", "No tmp files leaked"); + + unlink_new(\@before, \@after); + mkdir $ENV{TMPDIR}; ok(open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - works if TMPDIR points to an existent dir'); - # hardcoded default temp path - unlink ; + @after = glob $perlio_tmp_file_glob; + is( "@after", "@before", "No tmp files leaked"); + + unlink_new(\@before, \@after); } } +sub unlink_new { + my ($before, $after) = @_; + my %before; + @before{@$before} = (); + unlink grep {!exists $before{$_}} @$after; +} + # in-memory open SKIP: { eval { require PerlIO::scalar }; -- cgit v1.2.1