diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2019-07-03 13:48:09 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2019-07-03 13:48:09 +0000 |
commit | 4227b7a13fb9aad95d84c0e509cad30f1f3850e7 (patch) | |
tree | a5bd0e8a07865dc41c3f15d68a4c17c120fc35ce | |
parent | b74460174e8bf77ff7f53d9783758ad68c66f399 (diff) |
refine the error handling
useful to keep the last error from OpenBSD::Temp around, with all particulars
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Temp.pm | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Temp.pm b/usr.sbin/pkg_add/OpenBSD/Temp.pm index 0dde125363e..856f7ebd7be 100644 --- a/usr.sbin/pkg_add/OpenBSD/Temp.pm +++ b/usr.sbin/pkg_add/OpenBSD/Temp.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Temp.pm,v 1.30 2019/07/03 12:51:02 espie Exp $ +# $OpenBSD: Temp.pm,v 1.31 2019/07/03 13:48:08 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -29,6 +29,8 @@ our $tempbase = $ENV{'PKG_TMPDIR'} || OpenBSD::Paths->vartmp; my $dirs = {}; my $files = {}; +my ($lastname, $lasterror, $lasttype); + my $cleanup = sub { while (my ($name, $pid) = each %$files) { unlink($name) if $pid == $$; @@ -108,7 +110,12 @@ sub permanent_file if (defined $dir) { $template = "$dir/$template"; } - return OpenBSD::MkTemp::mkstemp($template); + if (my @l = OpenBSD::MkTemp::mkstemp($template)) { + return @l; + } + ($lastname, $lasttype, $lasterror) = ($template, 'file', $!); + return undef; + } sub permanent_dir @@ -118,12 +125,19 @@ sub permanent_dir if (defined $dir) { $template = "$dir/$template"; } - return OpenBSD::MkTemp::mkdtemp($template); + if (my @l = OpenBSD::MkTemp::mkdtemp($template)) { + return @l; + } + ($lastname, $lasttype, $lasterror) = ($template, 'dir', $!); + return undef; } -sub tempbase +sub last_error { - return $tempbase; -} + my ($class, $template) = @_; + my ($user) = getpwuid($>); + $template //= "User #1 couldn't create temp #2 as #3: #4"; + return ($template, $user, $lasttype, $lastname, $lasterror); +} 1; |