From d5e86a6fc9952b1eea07d5c14dc743fde7692d45 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 6 Jan 2005 10:13:04 +0000 Subject: - fs::format::part_raw() now takes $wait_message to allow displaying the progress of format - create fs::format::wait_message() which creates a $wait_message valid to give to fs::format::part - fs::format::mke2fs() format while parsing the output to display the progress --- perl-install/fs/format.pm | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'perl-install/fs') diff --git a/perl-install/fs/format.pm b/perl-install/fs/format.pm index c0f2f791f..7fd7d012e 100644 --- a/perl-install/fs/format.pm +++ b/perl-install/fs/format.pm @@ -49,12 +49,12 @@ sub part { loopback::format_part($part, $prefix); } else { $wait_message->(N("Formatting partition %s", $part->{device})) if $wait_message; - part_raw($part); + part_raw($part, $wait_message); } } sub part_raw { - my ($part) = @_; + my ($part, $wait_message) = @_; $part->{isFormatted} and return; @@ -82,7 +82,15 @@ sub part_raw { my ($_pkg, $cmd, @first_options) = @{$cmds{$fs_type} || die N("I do not know how to format %s in type %s", $part->{device}, $part->{fs_type})}; - run_program::raw({ timeout => 60 * 60 }, $cmd, @first_options, @options, devices::make($dev)) or die N("%s formatting of %s failed", $fs_type, $dev); + my @args = ($cmd, @first_options, @options, devices::make($dev)); + + my $time = time(); + if ($cmd eq 'mke2fs' && $wait_message) { + mke2fs($wait_message, @args) or die N("%s formatting of %s failed", $fs_type, $dev); + } else { + run_program::raw({ timeout => 60 * 60 }, @args) or die N("%s formatting of %s failed", $fs_type, $dev); + } + warn "$cmd took: ", formatTimeRaw(time() - $time); if ($fs_type eq 'ext3') { disable_forced_fsck($dev); @@ -91,9 +99,37 @@ sub part_raw { set_isFormatted($part, 1); } +sub mke2fs { + my ($wait_message, @args) = @_; + + open(my $F, "@args |"); + + local $/ = "\b"; + local $_; + while (<$F>) { + $wait_message->('', $1, $2) if m!^\s*(\d+)/(\d+)\b!; + } + return close($F); +} + sub disable_forced_fsck { my ($dev) = @_; run_program::run("tune2fs", "-c0", "-i0", devices::make($dev)); } +sub wait_message { + my ($in) = @_; + + my $w; + $w, sub { + my ($msg, $current, $total) = @_; + if ($msg) { + $w ||= $in->wait_message('', $msg); + $w->set($msg); + } elsif ($total) { + $w->set("$current / $total"); + } + }; +} + 1; -- cgit v1.2.1