# ex:ts=8 sw=4:
-# $OpenBSD: Temp.pm,v 1.27 2015/03/04 13:55:32 espie Exp $
+# $OpenBSD: Temp.pm,v 1.28 2018/02/10 10:08:05 espie Exp $
#
# Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org>
#
return "$dir/";
}
-sub file
+sub fh_file
{
+ my ($stem, $cleanup) = @_;
my $caught;
my $h = sub { $caught = shift; };
my ($fh, $file);
local $SIG{'HUP'} = $h;
local $SIG{'KILL'} = $h;
local $SIG{'TERM'} = $h;
- ($fh, $file) = permanent_file($tempbase, "pkgout");
+ ($fh, $file) = permanent_file($tempbase, $stem);
if (defined $file) {
- $files->{$file} = $$;
+ &$cleanup($file);
}
}
if (defined $caught) {
kill $caught, $$;
}
- return $file;
+ return ($fh, $file);
+}
+
+sub file
+{
+ return (fh_file("pkgout", sub { $files->{shift} = $$; })) [1];
}
sub reclaim