summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/pkg_add/Makefile3
-rw-r--r--usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm83
-rw-r--r--usr.sbin/pkg_add/pkg_add38
-rw-r--r--usr.sbin/pkg_add/pkg_delete29
4 files changed, 135 insertions, 18 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile
index b5646251f4e..93a2d794ea0 100644
--- a/usr.sbin/pkg_add/Makefile
+++ b/usr.sbin/pkg_add/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.11 2004/10/11 09:44:06 espie Exp $
+# $OpenBSD: Makefile,v 1.12 2004/10/18 12:03:19 espie Exp $
MAN=pkg_add.1 pkg_info.1 pkg_create.1 pkg_delete.1 pkg.1
@@ -16,6 +16,7 @@ PACKAGES= \
OpenBSD/PackingOld.pm \
OpenBSD/PkgCfl.pm \
OpenBSD/PkgSpec.pm \
+ OpenBSD/ProgressMeter.pm \
OpenBSD/RequiredBy.pm \
OpenBSD/Temp.pm \
OpenBSD/Ustar.pm \
diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
new file mode 100644
index 00000000000..24461fe2cee
--- /dev/null
+++ b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
@@ -0,0 +1,83 @@
+# ex:ts=8 sw=4:
+# $OpenBSD: ProgressMeter.pm,v 1.1 2004/10/18 12:03:19 espie Exp $
+#
+# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+#
+
+use strict;
+use warnings;
+
+package OpenBSD::ProgressMeter;
+
+my $header;
+my $lastdisplay = '';
+my $isatty;
+my $enabled = 0;
+
+# unless we know better
+my $width = 80;
+my $playfield;
+
+sub enable
+{
+ $enabled = 1;
+}
+
+sub set_header
+{
+ $header = shift;
+ if (!$enabled) {
+ $isatty = 0;
+ } else {
+ if (!defined $isatty) {
+ $isatty = -t STDERR;
+ }
+ }
+ if ($isatty) {
+ # compute playfield
+ $playfield = $width - length($header) - 10;
+ if ($playfield > 40) {
+ $playfield = 40;
+ }
+ }
+ return $isatty;
+}
+
+sub show
+{
+ my ($current, $total) = @_;
+ return unless $isatty;
+
+ my $stars = ($current * $playfield) / $total;
+ my $percent = int (($current * 100)/$total + 0.5);
+ my $d = "$header|".'*'x$stars.' 'x($playfield-$stars)."| ".$percent."\%";
+ return if $d eq $lastdisplay;
+ $lastdisplay=$d;
+ print STDERR $d, "\r";
+}
+
+sub clear
+{
+ return unless $isatty;
+ print STDERR ' 'x length($lastdisplay), "\r";
+}
+
+sub next
+{
+ return unless $isatty;
+ clear;
+ print STDERR"$header: complete\n";
+}
+
+1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index fb327f789e7..1a1d3c2b573 100644
--- a/usr.sbin/pkg_add/pkg_add
+++ b/usr.sbin/pkg_add/pkg_add
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_add,v 1.81 2004/10/18 11:12:21 espie Exp $
+# $OpenBSD: pkg_add,v 1.82 2004/10/18 12:03:19 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -29,6 +29,7 @@ use OpenBSD::PkgSpec;
use OpenBSD::Vstat;
use OpenBSD::Getopt;
use OpenBSD::Error;
+use OpenBSD::ProgressMeter;
use File::Copy;
our %forced = ();
@@ -395,9 +396,9 @@ sub fill_conflict_lists
my $errors = 0;
-our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q);
+our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_f, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q, $opt_x);
$opt_v = 0;
-getopts('avnIL:f:B:A:P:Q:',
+getopts('avnxIL:f:B:A:P:Q:',
{'v' => sub {++$opt_v;} });
if ($opt_f) {
%forced = map {($_, 1)} split(/,/, $opt_f);
@@ -413,6 +414,9 @@ if ($opt_P) {
Fatal "bad option: -P $opt_P";
}
}
+if ($opt_x) {
+ OpenBSD::ProgressMeter::enable();
+}
$opt_L = '/usr/local' unless defined $opt_L;
@@ -715,6 +719,7 @@ sub validate_plist($$)
my $problems = 0;
my $pkgname = $plist->pkgname();
+ my $totsize = 0;
my $extra = $plist->{extrainfo};
if ($cdrom_only && ((!defined $extra) || $extra->{cdrom} ne 'yes')) {
@@ -735,6 +740,7 @@ sub validate_plist($$)
push(@$colliding, $fname);
$problems++;
}
+ $totsize += $item->{size} if defined $item->{size};
my $s = OpenBSD::Vstat::add($fname, $item->{size});
next unless defined $s;
if ($s->{ro}) {
@@ -750,6 +756,7 @@ sub validate_plist($$)
collision_report($colliding);
}
Fatal "fatal issues" if $problems;
+ return $totsize;
}
sub do_script
@@ -788,16 +795,20 @@ sub really_add($$)
$state->{dir} = $dir;
$state->{pkgname} = $pkgname;
+ my $header = $pkgname;
+
if (defined $state->{deptree}->{$pkgname}) {
- print $state->{deptree}->{$pkgname},":";
+ $header = $state->{deptree}->{$pkgname}.":".$header;
}
- print $state->{not} ? "Pretending to add " : "Adding ";
- print $pkgname;
- if ($state->{do_faked}) {
- print " under ", $state->{destdir};
+ if (!OpenBSD::ProgressMeter::set_header($header)) {
+ print $state->{not} ? "Pretending to add " : "Adding ";
+ print $header;
+ if ($state->{do_faked}) {
+ print " under ", $state->{destdir};
+ }
+ print "\n";
}
- print "\n";
- validate_plist($plist, $destdir) unless $state->{do_faked};
+ my $totsize = validate_plist($plist, $destdir);
if (!defined $handle) {
Fatal "Archive in $pkgname broken";
@@ -815,6 +826,7 @@ sub really_add($$)
do_script($plist, INSTALL, $state, "PRE-INSTALL");
$plist->{done} = [];
+ my $donesize = 0;
$state->{end_faked} = 0;
for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) {
eval { $item->install($state); };
@@ -824,6 +836,11 @@ sub really_add($$)
last;
}
push(@{$plist->{done}}, $item);
+ if (defined $item->{size}) {
+ $donesize += $item->{size};
+ OpenBSD::ProgressMeter::show($donesize, $totsize);
+ }
+
last if $interrupted;
# stop faked installation there...
if ($state->{do_faked} && $state->{end_faked}) {
@@ -832,6 +849,7 @@ sub really_add($$)
}
$handle->close();
+ OpenBSD::ProgressMeter::next();
if (!$interrupted) {
eval { do_script($plist, INSTALL, $state, "POST-INSTALL") };
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 92691e58d88..18d5cc467fb 100644
--- a/usr.sbin/pkg_add/pkg_delete
+++ b/usr.sbin/pkg_add/pkg_delete
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_delete,v 1.58 2004/10/18 10:51:03 espie Exp $
+# $OpenBSD: pkg_delete,v 1.59 2004/10/18 12:03:19 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -27,6 +27,7 @@ use OpenBSD::Logger;
use OpenBSD::Vstat;
use OpenBSD::PackageInfo;
use OpenBSD::Error;
+use OpenBSD::ProgressMeter;
our %forced = ();
@@ -471,7 +472,7 @@ sub delete
package main;
-our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_f, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B, $opt_I);
+our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_f, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B, $opt_I, $opt_x);
$opt_v = 0;
sub remove_packing_info
@@ -506,9 +507,11 @@ sub validate_plist($$)
my ($plist, $destdir) = @_;
my $problems = 0;
+ my $totsize = 0;
for my $item (@{$plist->{items}}) {
next unless $item->IsFile();
my $fname = $destdir.$item->fullname();
+ $totsize += $item->{size} if defined $item->{size};
my $s = OpenBSD::Vstat::remove($fname, $item->{size});
next unless defined $s;
if ($s->{ro}) {
@@ -517,6 +520,7 @@ sub validate_plist($$)
}
}
Fatal "fatal issues" if $problems;
+ return $totsize;
}
sub delete_package
@@ -534,7 +538,7 @@ sub delete_package
Fatal "Package $pkgname real name does not match";
}
- validate_plist($plist, $state->{destdir});
+ my $totsize = validate_plist($plist, $state->{destdir});
$ENV{'PKG_PREFIX'} = $plist->pkgbase();
if ($plist->has(REQUIRE)) {
@@ -545,10 +549,16 @@ sub delete_package
}
$plist->visit('register_manpage', $state);
manpages_unindex($state);
+ my $donesize = 0;
for my $item (@{$plist->{groups}}, @{$plist->{users}}, @{$plist->{items}}) {
$item->delete($state);
+ if (defined $item->{size}) {
+ $donesize += $item->{size};
+ OpenBSD::ProgressMeter::show($donesize, $totsize);
+ }
}
+ OpenBSD::ProgressMeter::next();
if ($plist->has(UNDISPLAY)) {
$plist->get(UNDISPLAY)->prepare($state);
}
@@ -569,7 +579,7 @@ sub delete_package
remove_packing_info($dir) unless $opt_n;
}
-getopts('vcDdnf:qpS:L:B:I',
+getopts('vcxDdnf:qpS:L:B:I',
{'v' => sub {++$opt_v;} });
if ($opt_D) {
$opt_I = 1;
@@ -590,6 +600,9 @@ if (defined $opt_d) {
Fatal "Option d is obsolete";
}
+if ($opt_x) {
+ OpenBSD::ProgressMeter::enable();
+}
if ($opt_f) {
%forced = map {($_, 1)} split(/,/, $opt_f);
}
@@ -702,8 +715,10 @@ eval {
}
my $deps = OpenBSD::RequiredBy->new($pkgname)->list();
next if @$deps > 0;
- print $opt_n ? "Pretending to delete " : "Deleting ",
- "$pkgname\n";
+ if (!OpenBSD::ProgressMeter::set_header($pkgname)) {
+ print $opt_n ? "Pretending to delete " : "Deleting ",
+ "$pkgname\n";
+ }
$state->{pkgname_tolog} = $pkgname;
delete_package($pkgname, $state);
delete_installed($pkgname);
@@ -732,5 +747,5 @@ if (defined $logname) {
print "Problems logged as $logname\n";
}
if ($dielater) {
- die $@;
+ die $dielater;
}