]> git.proxmox.com Git - pve-common.git/commitdiff
new helper PVE::Tools::du() - get disk usage
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 25 Apr 2018 08:29:58 +0000 (10:29 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 25 Apr 2018 08:29:58 +0000 (10:29 +0200)
We simply call the external binary 'du', so that we can abort the command
when we run into a timeout.

src/PVE/Tools.pm

index 6a2dae46d37d8e4cfff2dd60b46f8a80ae4e2e84..1c5b50296a0149a8eed65e34996e464e5dda3fff 100644 (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:
 # UPID helper
 # We use this to uniquely identify a process.
 # An 'Unique Process ID' has the following format: