4 static gboolean option_use_async
;
5 static gint option_format_size
;
7 static gint outstanding_asyncs
;
10 print_result (const gchar
*filename
,
19 if (option_format_size
)
21 GFormatSizeFlags format_flags
;
24 format_flags
= (option_format_size
> 1) ? G_FORMAT_SIZE_LONG_FORMAT
: G_FORMAT_SIZE_DEFAULT
;
25 str
= g_format_size_full (disk_usage
, format_flags
);
26 g_print ("%s: %s (%"G_GUINT64_FORMAT
" dirs, %"G_GUINT64_FORMAT
" files)%c",
27 filename
, str
, num_dirs
, num_files
, nl
);
31 g_print ("%s: %"G_GUINT64_FORMAT
" (%"G_GUINT64_FORMAT
" dirs, %"G_GUINT64_FORMAT
" files)%c",
32 filename
, disk_usage
, num_dirs
, num_files
, nl
);
36 g_printerr ("%s: %s\n", filename
, error
->message
);
42 async_ready_func (GObject
*source
,
46 gchar
*filename
= user_data
;
52 g_file_measure_disk_usage_finish (G_FILE (source
), result
, &disk_usage
, &num_dirs
, &num_files
, &error
);
53 print_result (filename
, disk_usage
, num_dirs
, num_files
, error
, '\n');
59 report_progress (gboolean reporting
,
65 const gchar
*filename
= user_data
;
68 g_printerr ("%s: warning: does not support progress reporting\n", filename
);
70 print_result (filename
, disk_usage
, num_dirs
, num_files
, NULL
, '\r');
74 main (int argc
, char **argv
)
76 GFileMeasureProgressCallback progress
= NULL
;
77 GFileMeasureFlags flags
= 0;
81 argv
= g_win32_get_command_line ();
82 argc
= g_strv_length (argv
);
85 setlocale (LC_ALL
, "");
89 for (i
= 1; argv
[i
] && argv
[i
][0] == '-'; i
++)
91 if (g_str_equal (argv
[i
], "--"))
94 if (g_str_equal (argv
[i
], "--help"))
96 g_print ("usage: du [--progress] [--async] [-x] [-h] [-h] [--apparent-size] [--any-error] [--] files...\n");
102 else if (g_str_equal (argv
[i
], "-x"))
103 flags
|= G_FILE_MEASURE_NO_XDEV
;
104 else if (g_str_equal (argv
[i
], "-h"))
105 option_format_size
++;
106 else if (g_str_equal (argv
[i
], "--apparent-size"))
107 flags
|= G_FILE_MEASURE_APPARENT_SIZE
;
108 else if (g_str_equal (argv
[i
], "--any-error"))
109 flags
|= G_FILE_MEASURE_REPORT_ANY_ERROR
;
110 else if (g_str_equal (argv
[i
], "--async"))
111 option_use_async
= TRUE
;
112 else if (g_str_equal (argv
[i
], "--progress"))
113 progress
= report_progress
;
116 g_printerr ("unrecognised flag %s\n", argv
[i
]);
122 g_printerr ("usage: du [--progress] [--async] [-x] [-h] [-h] [--apparent-size] [--any-error] [--] files...\n");
131 GFile
*file
= g_file_new_for_commandline_arg (argv
[i
]);
133 if (option_use_async
)
135 g_file_measure_disk_usage_async (file
, flags
, G_PRIORITY_DEFAULT
, NULL
,
136 progress
, argv
[i
], async_ready_func
, argv
[i
]);
137 outstanding_asyncs
++;
141 GError
*error
= NULL
;
146 g_file_measure_disk_usage (file
, flags
, NULL
, progress
, argv
[i
],
147 &disk_usage
, &num_dirs
, &num_files
, &error
);
148 print_result (argv
[i
], disk_usage
, num_dirs
, num_files
, error
, '\n');
151 g_object_unref (file
);
156 while (outstanding_asyncs
)
157 g_main_context_iteration (NULL
, TRUE
);