From 128ea67c45407625d533bf76ff5f93c4adb56443 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Thu, 30 Oct 2008 21:38:57 +0000 Subject: factorize rsync progress update code --- draklive | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/draklive b/draklive index a596b4f..ae2ae9e 100755 --- a/draklive +++ b/draklive @@ -796,24 +796,12 @@ sub record_usb_master { do { my $loopbacks_source = $live->get_builddir . $live->{prefix}{build}{loopbacks} . '/'; my $total = directory_usage($loopbacks_source); - my $all_files = 0; - my $current_file = 0; my $list_file = tmpnam(); output_p($list_file, map { ".$_\n" } list_selected_loopbacks($live)); local $/ = "\r"; - my $r = run_foreach( - $live->{update_progress} ? sub { - if (/^\s*(\d+)\s+\d+%\s+/) { - $current_file = $1; - $live->{update_progress}->(undef, $all_files + $current_file, $total); - } - if (/(?:^|\n)\S+/) { - $all_files += $current_file; - $current_file = 0; - } - } : sub { print }, - 'rsync', '-vdP', '--inplace', '--files-from=' . $list_file, - $loopbacks_source, $live->{mnt} . $media_loopbacks, + my $r = run_foreach(update_progress_rsync($live, $total), + 'rsync', '-vdP', '--inplace', '--files-from=' . $list_file, + $loopbacks_source, $live->{mnt} . $media_loopbacks, ); unlink $list_file; if (!$r) { @@ -856,22 +844,8 @@ sub record_harddisk_master { do { my $source = $live->get_system_root; my $total = directory_usage($source); - my $all_files = 0; - my $current_file = 0; local $/ = "\r"; - my $r = run_foreach( - $live->{update_progress} ? sub { - if (/^\s*(\d+)\s+\d+%\s+/) { - $current_file = $1; - $live->{update_progress}->(undef, $all_files + $current_file, $total); - } - if (/(?:^|\n)\S+/) { - $all_files += $current_file; - $current_file = 0; - } - } : sub { print }, - 'rsync', '-avP', $source . '/', $live->{mnt}, - ); + my $r = run_foreach(update_progress_rsync($live, $total), 'rsync', '-avP', $source . '/', $live->{mnt}); if (!$r) { run_('umount', $live->{mnt}); maybe_umount_device($device); @@ -1044,6 +1018,22 @@ sub create_replicator { } } +sub update_progress_rsync { + my ($live, $total) = @_; + my $all_files = 0; + my $current_file = 0; + $live->{update_progress} ? sub { + if (/^\s*(\d+)\s+\d+%\s+/) { + $current_file = $1; + $live->{update_progress}->(undef, $all_files + $current_file, $total); + } + if (/(?:^|\n)\S+/) { + $all_files += $current_file; + $current_file = 0; + } + } : sub { print }; +} + sub copy_wizard { my ($live) = @_; -- cgit v1.2.1