diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2005-06-08 09:43:41 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2005-06-08 09:43:41 +0000 |
commit | af2fdbe35f7dd292d78dfcc90e7dc08e7b0fc2f8 (patch) | |
tree | 1d11dce39079b12f47a088909d4dd713fa154032 /usr.sbin/pkg_add | |
parent | 01a9dcd38277c6a74e443a1c37da6e00dfde6507 (diff) |
squeeze +COMMENT in front of +DESC.
Transparently handle both package types, until everyone has
transitionned to new style.
Reasons for the change:
- comment and desc are never written independently
- access to comment necessitates a file read anyways.
- shaves one inode and (mostly) one block from each installed package.
Since this is /var, and there is often a lot of stuff going on in a small
partition, this helps.
Done after griping from tedu@, okay'd pval@
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/pkg_create | 24 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_info | 27 |
2 files changed, 35 insertions, 16 deletions
diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create index 6c7bb1eca86..318c625b224 100644 --- a/usr.sbin/pkg_add/pkg_create +++ b/usr.sbin/pkg_add/pkg_create @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_create,v 1.33 2005/01/22 12:52:55 espie Exp $ +# $OpenBSD: pkg_create,v 1.34 2005/06/08 09:43:40 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -228,9 +228,9 @@ sub dosubst sub copy_subst { - my ($srcname, $destname) = @_; + my ($srcname, $mode, $destname) = @_; open my $src, '<', $srcname or die "can't open $srcname"; - open my $dest, '>', $destname or die "can't open $destname"; + open my $dest, $mode, $destname or die "can't open $destname"; local $_; while (<$src>) { print $dest dosubst($_); @@ -330,11 +330,11 @@ if (!@contents) { if (defined $opt_c) { if ($opt_c =~ /^\-/) { - open(my $fh, '>', $dir.COMMENT) or die "Can't write to COMMENT: $!"; + open(my $fh, '>', $dir.DESC) or die "Can't write COMMENT to DESC file: $!"; print $fh $'; close($fh); } else { - copy_subst($opt_c, $dir.COMMENT); + copy_subst($opt_c, '>', $dir.DESC); } } else { Usage "Comment required" unless $regen_package; @@ -342,11 +342,11 @@ if (defined $opt_c) { if (defined $opt_d) { if ($opt_d =~ /^\-/) { - open(my $fh, '>', $dir.DESC) or die "Can't write to DESC: $!"; + open(my $fh, '>>', $dir.DESC) or die "Can't write to DESC: $!"; print $fh $'; close($fh); } else { - copy_subst($opt_d, $dir.DESC); + copy_subst($opt_d, '>>', $dir.DESC); } } else { Usage "Description required" unless $regen_package; @@ -355,23 +355,23 @@ if (defined $opt_d) { print "Creating package $ARGV[0]\n" if $opt_v && !$regen_package; if (defined $opt_i) { - copy_subst($opt_i, $dir.INSTALL); + copy_subst($opt_i, '>', $dir.INSTALL); } if (defined $opt_k) { - copy_subst($opt_k, $dir.DEINSTALL); + copy_subst($opt_k, '>', $dir.DEINSTALL); } if (defined $opt_r) { - copy_subst($opt_r, $dir.REQUIRE); + copy_subst($opt_r, '>', $dir.REQUIRE); } if (defined $opt_M) { - copy_subst($opt_M, $dir.DISPLAY); + copy_subst($opt_M, '>', $dir.DISPLAY); } if (defined $opt_U) { - copy_subst($opt_U, $dir.UNDISPLAY); + copy_subst($opt_U, '>', $dir.UNDISPLAY); } my @extra_files = (); diff --git a/usr.sbin/pkg_add/pkg_info b/usr.sbin/pkg_add/pkg_info index a9bbd4779cf..30ebb2a2c5d 100644 --- a/usr.sbin/pkg_add/pkg_info +++ b/usr.sbin/pkg_add/pkg_info @@ -1,6 +1,6 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_info,v 1.28 2005/01/16 11:16:23 espie Exp $ +# $OpenBSD: pkg_info,v 1.29 2005/06/08 09:43:40 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -64,6 +64,19 @@ sub printfile close $fh; } +sub print_description +{ + my $dir = shift; + local $_; + + open my $fh, '<', $dir.DESC or return; + $_ = <$fh> unless -f $dir.COMMENT; + while(<$fh>) { + print; + } + close $fh; +} + sub get_line { open my $fh, '<', shift or return ""; @@ -73,6 +86,12 @@ sub get_line return $c; } +sub get_comment +{ + my $d = shift; + return get_line(-f $d.COMMENT? $d.COMMENT : $d.DESC); +} + sub find_by_spec { my $pat = shift; @@ -153,7 +172,7 @@ sub print_info if ($opt_I) { my $l = 20 - length($pkg); $l = 1 if $l <= 0; - print $pkg, " "x$l, get_line($dir.COMMENT), "\n"; + print $pkg, " "x$l, get_comment($dir), "\n"; } else { if ($terse) { print $opt_l, $pkg, "\n" unless $opt_q; @@ -162,7 +181,7 @@ sub print_info } if ($opt_c) { print $opt_l, "Comment:\n" unless $opt_q; - printfile($dir.COMMENT); + print get_comment($dir), "\n"; print "\n"; } if ($opt_R && -f $dir.REQUIRED_BY) { @@ -172,7 +191,7 @@ sub print_info } if ($opt_d) { print $opt_l, "Description:\n" unless $opt_q; - printfile($dir.DESC); + print_description($dir); print "\n"; } if ($opt_M && -f $dir.DISPLAY) { |