5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-02-25 21:57:42 +03:00

new helper PVE::Tools::du() - get disk usage

We simply call the external binary 'du', so that we can abort the command
when we run into a timeout.
This commit is contained in:
Dietmar Maurer 2018-04-25 10:29:58 +02:00
parent fd58bb2bff
commit 62635f9235

View File

@ -997,6 +997,26 @@ sub df {
};
}
sub du {
my ($path, $timeout) = @_;
my $size;
$timeout //= 10;
my $parser = sub {
my $line = shift;
if ($line =~ m/^(\d+)\s+total$/) {
$size = $1;
}
};
run_command(['du', '-scb', $path], outfunc => $parser, timeout => $timeout);
return $size;
}
# UPID helper
# We use this to uniquely identify a process.
# An 'Unique Process ID' has the following format: