file_size_info: move parser to own variable

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2019-09-09 15:36:14 +02:00
parent aa4594b1d1
commit 1dbbd5abd6

View File

@ -712,15 +712,12 @@ sub file_size_info {
return wantarray ? (0, 'subvol', 0, undef) : 1; return wantarray ? (0, 'subvol', 0, undef) : 1;
} }
my $cmd = ['/usr/bin/qemu-img', 'info', $filename];
my $format; my $format;
my $parent; my $parent;
my $size = 0; my $size = 0;
my $used = 0; my $used = 0;
eval { my $parse_qemu_img_info = sub {
run_command($cmd, timeout => $timeout, outfunc => sub {
my $line = shift; my $line = shift;
if ($line =~ m/^file format:\s+(\S+)\s*$/) { if ($line =~ m/^file format:\s+(\S+)\s*$/) {
$format = $1; $format = $1;
@ -739,9 +736,12 @@ sub file_size_info {
$used = int($used); $used = int($used);
} }
});
}; };
my $cmd = ['/usr/bin/qemu-img', 'info', $filename];
eval {
run_command($cmd, timeout => $timeout, outfunc => $parse_qemu_img_info );
};
warn $@ if $@; warn $@ if $@;
return wantarray ? ($size, $format, $used, $parent) : $size; return wantarray ? ($size, $format, $used, $parent) : $size;