(* Guestfs Browser.
* Copyright (C) 2011 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
open Utils
open Printf
let rec disk_usage tree path =
let model = tree#model in
let row = model#get_iter path in
let src, pathname = tree#get_pathname row in
debug "disk_usage %s" pathname;
(* See if this node already has an Info "disk_usage" child node. If
* so they don't recreate it.
*)
let info_text = "disk_usage" in
if not (tree#has_child_info_node path info_text) then (
tree#set_child_info_node path info_text "Calculating disk usage ...";
Slave.disk_usage src pathname (when_disk_usage tree path pathname)
)
and when_disk_usage tree path pathname kbytes =
let model = tree#model in
let row = model#get_iter path in
tree#set_visited row;
(* Find the Info "disk_usage" child node added above, and replace the
* text in it with the final size.
*)
let info_text = "disk_usage" in
let msg =
sprintf "%s\nDisk usage of %s (%Ld KB)"
(human_size_1k kbytes) pathname kbytes in
tree#set_child_info_node path info_text msg