From 10d338baa8705caabf673bcb602e75c9c3f5c07e Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Fri, 6 Dec 2024 17:25:19 +0100 Subject: [PATCH] file size info: introduce error handling helper Signed-off-by: Fiona Ebner --- src/PVE/Storage/Plugin.pm | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 0b0b5a8..d90f5a1 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -971,6 +971,16 @@ sub file_size_info { } } + my $handle_error = sub { + my ($msg) = @_; + if ($untrusted) { + die $msg; + } else { + warn $msg; + return wantarray ? (undef, undef, undef, undef, $st->ctime) : undef; + } + }; + if (S_ISDIR($st->mode)) { return wantarray ? (0, 'subvol', 0, undef, $st->ctime) : 1; } @@ -998,15 +1008,7 @@ sub file_size_info { } my $info = eval { decode_json($json) }; - if (my $err = $@) { - my $msg = "could not parse qemu-img info command output for '$filename' - $err\n"; - if ($untrusted) { - die $msg; - } else { - warn $msg; - return wantarray ? (undef, undef, undef, undef, $st->ctime) : undef; - } - } + $handle_error->("could not parse qemu-img info command output for '$filename' - $@\n") if $@; if ($untrusted) { if (my $format_specific = $info->{'format-specific'}) {