diff options
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/common.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/perl-install/common.pm b/perl-install/common.pm index 32854daed..3eb223cd5 100644 --- a/perl-install/common.pm +++ b/perl-install/common.pm @@ -271,6 +271,29 @@ sub secured_file { $f; } +sub unwind_protect { + my ($to_do, $cleanup) = @_; + my @l = eval { $to_do->() }; + my $err = $@; + $cleanup->(); + $err and die $err; + wantarray() ? @l : $l[0]; +} + +sub with_private_tmp_file { + my ($file, $content, $f) = @_; + + my $prev_umask = umask 077; + + unwind_protect(sub { + MDK::Common::File::secured_output($file, $content); + $f->($file); + }, sub { + umask $prev_umask; + unlink $file; + }); +} + sub chown_ { my ($b_recursive, $name, $group, @files) = @_; |