[pve-devel] [PATCH storage 2/3] Create run_with_umask helper
Fabian Ebner
f.ebner at proxmox.com
Thu Dec 12 11:17:18 CET 2019
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
Only makes sense together with patch 3.
PVE/Storage.pm | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index ae2ea53..3e65e06 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -103,6 +103,17 @@ my $UDEVADM = '/sbin/udevadm';
our $iso_extension_re = qr/\.(?:iso|img)/i;
+my $run_with_umask = sub {
+ my ($umask, $func, @param) = @_;
+
+ my $old_umask = umask($umask);
+ my $res = eval { $func->(@param) };
+ my $err = $@;
+ umask $old_umask;
+ die $err if $err;
+ return $res;
+};
+
# PVE::Storage utility functions
sub config {
@@ -734,11 +745,9 @@ sub vdisk_alloc {
# lock shared storage
return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
- my $old_umask = umask(umask|0037);
- my $volname = eval { $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size) };
- my $err = $@;
- umask $old_umask;
- die $err if $err;
+ my $volname = $run_with_umask->(umask|0037, sub {
+ return $plugin->alloc_image($storeid, $scfg, $vmid, $fmt, $name, $size);
+ });
return "$storeid:$volname";
});
}
--
2.20.1
More information about the pve-devel
mailing list