slave: Use slightly modified event_callback.
[guestfs-browser.git] / op_disk_usage.ml
1 (* Guestfs Browser.
2  * Copyright (C) 2011 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *)
18
19 open Utils
20
21 open Printf
22
23 let rec disk_usage tree path =
24   let model = tree#model in
25   let row = model#get_iter path in
26   let src, pathname = tree#get_pathname row in
27   debug "disk_usage %s" pathname;
28
29   (* See if this node already has an Info "disk_usage" child node.  If
30    * so they don't recreate it.
31    *)
32   let info_text = "disk_usage" in
33   if not (tree#has_child_info_node path info_text) then (
34     tree#set_child_info_node path info_text "<i>Calculating disk usage ...</i>";
35
36     Slave.disk_usage src pathname (when_disk_usage tree path pathname)
37   )
38
39 and when_disk_usage tree path pathname kbytes =
40   let model = tree#model in
41   let row = model#get_iter path in
42   tree#set_visited row;
43
44   (* Find the Info "disk_usage" child node added above, and replace the
45    * text in it with the final size.
46    *)
47   let info_text = "disk_usage" in
48   let msg =
49     sprintf "<b>%s</b>\n<small>Disk usage of %s (%Ld KB)</small>"
50       (human_size_1k kbytes) pathname kbytes in
51   tree#set_child_info_node path info_text msg