5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2024-12-22 13:34:16 +03:00

file size info: introduce error handling helper

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2024-12-06 17:25:19 +01:00 committed by Fabian Grünbichler
parent 4836e98901
commit 10d338baa8

View File

@ -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'}) {