From 62635f92356f82e76b044fcc74ccd4e1d624637a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 25 Apr 2018 10:29:58 +0200 Subject: [PATCH] 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. --- src/PVE/Tools.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 6a2dae4..1c5b502 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -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: -- 2.39.2