diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-09-18 14:19:04 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-09-18 14:19:04 +0000 |
commit | dfd77a5ef5d5443794045fbb24357edcb40202b2 (patch) | |
tree | 9309201108b68eae8e233bc50f6f14690633f915 /perl-install | |
parent | b67f698d698065a273d3e9a652db554d7fa35ee8 (diff) | |
download | drakx-dfd77a5ef5d5443794045fbb24357edcb40202b2.tar drakx-dfd77a5ef5d5443794045fbb24357edcb40202b2.tar.gz drakx-dfd77a5ef5d5443794045fbb24357edcb40202b2.tar.bz2 drakx-dfd77a5ef5d5443794045fbb24357edcb40202b2.tar.xz drakx-dfd77a5ef5d5443794045fbb24357edcb40202b2.zip |
create unwind_protect() and with_private_tmp_file()
(for future use)
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) = @_; |