summaryrefslogtreecommitdiffstats
path: root/perl-install
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-09-18 14:19:04 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-09-18 14:19:04 +0000
commitdfd77a5ef5d5443794045fbb24357edcb40202b2 (patch)
tree9309201108b68eae8e233bc50f6f14690633f915 /perl-install
parentb67f698d698065a273d3e9a652db554d7fa35ee8 (diff)
downloaddrakx-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.pm23
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) = @_;