From b4e830357171338fbc62616ac87217e6ab3af4ba Mon Sep 17 00:00:00 2001 From: Francois Pons Date: Thu, 23 Jan 2003 14:30:04 +0000 Subject: 4.2-10mdk --- urpm.pm | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- urpmi | 11 ++++++++--- urpmi.spec | 6 +++++- 3 files changed, 63 insertions(+), 12 deletions(-) diff --git a/urpm.pm b/urpm.pm index 3d746ff0..dfd8bebf 100644 --- a/urpm.pm +++ b/urpm.pm @@ -348,11 +348,30 @@ sub sync_rsync { foreach (@_) { my $count = 10; #- retry count on error (if file exists). my $basename = (/^.*\/([^\/]*)$/ && $1) || $_; + my ($file) = /^rsync:\/\/(.*)/ or next; + ref $options && $options->{callback} and $options->{callback}('start', $file); do { - /^rsync:\/\/(.*)/ or next; - system "/usr/bin/rsync", (ref $options && $options->{quiet} ? qw(-q) : qw(--progress -v)), - qw(--partial --no-whole-file), $1, (ref $options ? $options->{dir} : $options); + local (*RSYNC, $_); + my $buf = ''; + open RSYNC, "-|", "/usr/bin/rsync", (ref $options && $options->{quiet} ? qw(-q) : qw(--progress -v)), + qw(--partial --no-whole-file), $file, (ref $options ? $options->{dir} : $options); + local $/ = \1; #- read input by only one char, this is slow but very nice (and it works!). + while () { + $buf .= $_; + if ($_ eq "\r" || $_ eq "\n") { + if (ref $options && $options->{callback}) { + if (my ($percent, $speed) = $buf =~ /^\s*\d+\s+(\d+)%\s+(\S+)\s+/) { + $options->{callback}('progress', $file, $percent, undef, undef, $speed); + } + } else { + print STDERR $_; + } + $buf = ''; + } + } + close RSYNC; } while ($? != 0 && --$count > 0 && (-e (ref $options ? $options->{dir} : $options) . "/$basename")); + ref $options && $options->{callback} and $options->{callback}('end', $file); } $? == 0 or die _("rsync failed: exited with %d or signal %d\n", $? >> 8, $? & 127); } @@ -360,13 +379,32 @@ sub sync_ssh { -x "/usr/bin/rsync" or die _("rsync is missing\n"); -x "/usr/bin/ssh" or die _("ssh is missing\n"); my $options = shift @_; - foreach (@_) { + foreach my $file (@_) { my $count = 10; #- retry count on error (if file exists). - my $basename = (/^.*\/([^\/]*)$/ && $1) || $_; + my $basename = ($file =~ /^.*\/([^\/]*)$/ && $1) || $file; + ref $options && $options->{callback} and $options->{callback}('start', $file); do { - system "/usr/bin/rsync", (ref $options && $options->{quiet} ? qw(-q) : qw(--progress -v)), qw(--partial -e ssh), - $_, (ref $options ? $options->{dir} : $options); + local (*RSYNC, $_); + my $buf = ''; + open RSYNC, "-|", "/usr/bin/rsync", (ref $options && $options->{quiet} ? qw(-q) : qw(--progress -v)), + qw(--partial -e ssh), $file, (ref $options ? $options->{dir} : $options); + local $/ = \1; #- read input by only one char, this is slow but very nice (and it works!). + while () { + $buf .= $_; + if ($_ eq "\r" || $_ eq "\n") { + if (ref $options && $options->{callback}) { + if (my ($percent, $speed) = $buf =~ /^\s*\d+\s+(\d+)%\s+(\S+)\s+/) { + $options->{callback}('progress', $file, $percent, undef, undef, $speed); + } + } else { + print STDERR $_; + } + $buf = ''; + } + } + close RSYNC; } while ($? != 0 && --$count > 0 && (-e (ref $options ? $options->{dir} : $options) . "/$basename")); + ref $options && $options->{callback} and $options->{callback}('end', $file); } $? == 0 or die _("rsync failed: exited with %d or signal %d\n", $? >> 8, $? & 127); } @@ -377,7 +415,11 @@ sub sync_logger { $file =~ s|([^:]*://[^/:\@]*:)[^/:\@]*(\@.*)|$1xxxx$2|; #- if needed... print STDERR " $file\n"; } elsif ($mode eq 'progress') { - print STDERR _(" %s%% of %s, ETA = %s, speed = %s", $percent, $total, $eta, $speed) . "\r"; + if (defined $total && defined $eta) { + print STDERR _(" %s%% of %s completed, ETA = %s, speed = %s", $percent, $total, $eta, $speed) . "\r"; + } else { + print STDERR _(" %s%% completed, speed = %s", $percent, $speed) . "\r"; + } } elsif ($mode eq 'end') { print STDERR (" "x79)."\r"; } diff --git a/urpmi b/urpmi index a73eb11f..a4d4c105 100755 --- a/urpmi +++ b/urpmi @@ -488,10 +488,15 @@ my %sources = $urpm->download_source_packages($local_sources, $list, my ($mode, $file, $percent, $total, $eta, $speed) = @_; if ($mode eq 'start') { $file =~ s|([^:]*://[^/:\@]*:)[^/:\@]*(\@.*)|$1xxxx$2|; #- if needed... - print SAVEERR " $file\n"; + print STDERR " $file\n"; #- allow pass-protected url to be logged. } elsif ($mode eq 'progress') { - print SAVEERR _(" %s%% of %s, ETA = %s, speed = %s", - $percent, $total, $eta, $speed) . "\r"; + if (defined $total && defined $eta) { + print SAVEERR _(" %s%% of %s completed, ETA = %s, speed = %s", + $percent, $total, $eta, $speed) . "\r"; + } else { + print SAVEERR _(" %s%% completed, speed = %s", + $percent, $speed) . "\r"; + } } elsif ($mode eq 'end') { print SAVEERR (" "x79)."\r"; } diff --git a/urpmi.spec b/urpmi.spec index b2e76a52..d82263eb 100644 --- a/urpmi.spec +++ b/urpmi.spec @@ -2,7 +2,7 @@ Name: urpmi Version: 4.2 -Release: 9mdk +Release: 10mdk License: GPL Source0: %{name}.tar.bz2 Source1: %{name}.logrotate @@ -205,6 +205,10 @@ fi %changelog +* Thu Jan 23 2003 François Pons 4.2-10mdk +- added download log support for rsync and ssh protocol. +- make log not visible in log file instead url. + * Thu Jan 23 2003 François Pons 4.2-9mdk - fix bug 994 according to Gerard Patel. - added download log for urpmi.addmedia and urpmi.update. -- cgit v1.2.1