diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-07-13 00:35:40 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-07-13 00:35:40 +0000 |
commit | d7df5eee9ab59059bcec6446cd7f3abdf8f5dbba (patch) | |
tree | e523598aee40ed87dce0908d024912805f049809 | |
parent | 91bf365a584ba435feb2ba71bd90c9a831747b19 (diff) |
at pkg_create time, mark hard links with @link, and symlinks with @symlink,
instead of computing size and md5.
okay naddy@, sturm@
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 47 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingList.pm | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_create | 23 |
3 files changed, 67 insertions, 9 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index 2d7e5308844..40792fec9ca 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,4 +1,4 @@ -# $OpenBSD: PackingElement.pm,v 1.9 2004/06/21 16:33:45 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.10 2004/07/13 00:35:39 espie Exp $ # # Copyright (c) 2003 Marc Espie. # @@ -163,6 +163,12 @@ sub write if (defined $self->{size}) { print $fh "\@size ", $self->{size}, "\n"; } + if (defined $self->{symlink}) { + print $fh "\@symlink ", $self->{symlink}, "\n"; + } + if (defined $self->{link}) { + print $fh "\@link ", $self->{link}, "\n"; + } } sub destate @@ -216,6 +222,21 @@ sub add_size $self->{size} = $sz; } +# XXX symlink/hardlinks are properties of File, +# because we want to use inheritance for other stuff. + +sub make_symlink +{ + my ($self, $linkname) = @_; + $self->{symlink} = $linkname; +} + +sub make_hardlink +{ + my ($self, $linkname) = @_; + $self->{link} = $linkname; +} + sub IsFile() { 1 } package OpenBSD::PackingElement::Ignore; @@ -267,6 +288,30 @@ sub add return undef; } +package OpenBSD::PackingElement::symlink; +our @ISA=qw(OpenBSD::PackingElement); +__PACKAGE__->setKeyword('symlink'); + +sub add +{ + my ($class, $plist, @args) = @_; + + $plist->{state}->{lastfile}->make_symlink($'); + return undef; +} + +package OpenBSD::PackingElement::hardlink; +our @ISA=qw(OpenBSD::PackingElement); +__PACKAGE__->setKeyword('link'); + +sub add +{ + my ($class, $plist, @args) = @_; + + $plist->{state}->{lastfile}->make_hardlink($'); + return undef; +} + package OpenBSD::PackingElement::size; our @ISA=qw(OpenBSD::PackingElement); __PACKAGE__->setKeyword('size'); diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm index 7d87c4111de..1e3420b75fc 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm @@ -1,4 +1,4 @@ -# $OpenBSD: PackingList.pm,v 1.9 2004/07/05 09:22:40 espie Exp $ +# $OpenBSD: PackingList.pm,v 1.10 2004/07/13 00:35:39 espie Exp $ # # Copyright (c) 2003 Marc Espie. # @@ -107,7 +107,9 @@ MAINLOOP: if (m/^\@shared\b/) { &$cont($_); while(<$fh>) { - redo MAINLOOP unless m/^\@md5\b/ || m/^\@size\b/; + redo MAINLOOP unless m/^\@md5\b/ || + m/^\@size\b/ || m/^\@symlink\b/ || + m/^\@link\b/; &$cont($_); } } else { diff --git a/usr.sbin/pkg_add/pkg_create b/usr.sbin/pkg_add/pkg_create index eaf9a86511b..d9953187b20 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.11 2004/07/06 17:35:08 espie Exp $ +# $OpenBSD: pkg_create,v 1.12 2004/07/13 00:35:38 espie Exp $ # # Copyright (c) 2003 Marc Espie. # @@ -82,27 +82,38 @@ sub archive_cmd sub compute_checksum { - my ($self, $base) = @_; + my ($self, $base, $stash) = @_; my $fname = $self->fullname(); if (-l "$base/$fname") { - return if $base eq '/' or $base eq ''; my $value = readlink "$base/$fname"; + $self->make_symlink($value); + return if $base eq '/' or $base eq ''; if ($value =~ m/^\Q$base/) { print STDERR "Error in package: symlink $base/$fname refers to $value\n"; $main::errors++; } + } elsif (-f _) { + my ($dev, $ino, $size) = (stat _)[0,1,7]; + if (defined $stash->{"$dev/$ino"}) { + $self->make_hardlink($stash->{"$dev/$ino"}); + } else { + $stash->{"$dev/$ino"} = $fname; + $self->{md5} = OpenBSD::md5::fromfile("$base/$fname"); + $self->{size} = $size; + } } else { - $self->{md5} = OpenBSD::md5::fromfile("$base/$fname"); - $self->{size} = (stat "$base/$fname")[7]; + print STDERR "Error in package: $base/$fname does not exist\n"; + $main::errors++; } } sub makesum { my ($self, $base) = @_; + my $stash = {}; for my $item (@{$self->{items}}) { if ($item->IsFile()) { - compute_checksum($item, $base); + compute_checksum($item, $base, $stash); } } } |