file size info: introduce error handling helper
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
This commit is contained in:
committed by
Fabian Grünbichler
parent
4836e98901
commit
10d338baa8
@ -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)) {
|
if (S_ISDIR($st->mode)) {
|
||||||
return wantarray ? (0, 'subvol', 0, undef, $st->ctime) : 1;
|
return wantarray ? (0, 'subvol', 0, undef, $st->ctime) : 1;
|
||||||
}
|
}
|
||||||
@ -998,15 +1008,7 @@ sub file_size_info {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $info = eval { decode_json($json) };
|
my $info = eval { decode_json($json) };
|
||||||
if (my $err = $@) {
|
$handle_error->("could not parse qemu-img info command output for '$filename' - $@\n") if $@;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($untrusted) {
|
if ($untrusted) {
|
||||||
if (my $format_specific = $info->{'format-specific'}) {
|
if (my $format_specific = $info->{'format-specific'}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user