diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2004-11-01 15:45:03 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2004-11-01 15:45:03 +0000 |
commit | 8cfc58854a57f371d9043e27cc1e80f6d167d4f2 (patch) | |
tree | 29e9e916264ab05ae5d7070bf11b4bffa46549a2 /usr.sbin/pkg_add | |
parent | 6c4c450d2acff947fae77df81d4e19b7ae75c53a (diff) |
move all the checking prior to extraction to a `prepare_to_extract' function.
check that linknames match while we're at it.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 59 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 14 |
2 files changed, 49 insertions, 24 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 66f4e1902cd..8ebbf2759eb 100644 --- a/usr.sbin/pkg_add/OpenBSD/Add.pm +++ b/usr.sbin/pkg_add/OpenBSD/Add.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Add.pm,v 1.3 2004/11/01 14:30:00 espie Exp $ +# $OpenBSD: Add.pm,v 1.4 2004/11/01 15:45:02 espie Exp $ # # Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org> # @@ -163,6 +163,7 @@ sub install my $destdir = $state->{destdir}; if (defined $self->{tempname}) { + if (defined $self->{link}) { link($destdir.$self->{link}, $destdir.$fullname); } elsif (defined $self->{symlink}) { @@ -171,26 +172,58 @@ sub install rename($self->{tempname}, $destdir.$fullname); } } else { - my $file=$state->{archive}->next(); - if ($file->{name} ne $self->{name}) { - Fatal "Error: archive does not match", $file->{name}, "!=", - $self->{name}, "\n"; - } + my $file = $self->prepare_to_extract($state); print "extracting $destdir$fullname\n" if $state->{very_verbose}; return if $state->{not}; - $file->{name} = $fullname; - $file->{cwd} = $self->{cwd}; - $file->{destdir} = $destdir; - # faked installation are VERY weird - if (defined $self->{symlink} && $state->{do_faked}) { - $file->{linkname} = $destdir.$file->{linkname}; - } $file->create(); } $self->set_modes($destdir.$fullname); } +sub prepare_to_extract +{ + my ($self, $state) = @_; + my $fullname = $self->fullname(); + my $destdir = $state->{destdir}; + + my $file=$state->{archive}->next(); + if ($file->{name} ne $self->{name}) { + Fatal "Error: archive does not match ", $file->{name}, "!=", + $self->{name}, "\n"; + } + if (defined $self->{symlink} || $file->isSymLink()) { + unless (defined $self->{symlink} && $file->isSymLink()) { + Fatal "Error: bogus symlink ", $self->{name}, "\n"; + } + if ($self->{symlink} ne $file->{linkname}) { + Fatal "Error: archive sl does not match ", $file->{linkname}, "!=", + $self->{symlink}, "\n"; + } + } elsif (defined $self->{link} || $file->isHardLink()) { + unless (defined $self->{link} && $file->isHardLink()) { + Fatal "Error: bogus hardlink ", $self->{name}, "\n"; + } + my $linkname = $file->{linkname}; + if (defined $self->{cwd}) { + $linkname = $self->{cwd}.'/'.$linkname; + } + if ($self->{link} ne $linkname) { + Fatal "Error: archive hl does not match ", $linkname, "!=", + $self->{link}, "!!!\n"; + } + } + + $file->{name} = $fullname; + $file->{cwd} = $self->{cwd}; + $file->{destdir} = $destdir; + # faked installation are VERY weird + if (defined $self->{symlink} && $state->{do_faked}) { + $file->{linkname} = $destdir.$file->{linkname}; + } + return $file; +} + package OpenBSD::PackingElement::EndFake; sub install { diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm index 5ee7859e9e8..aa4bfe460d2 100644 --- a/usr.sbin/pkg_add/OpenBSD/Update.pm +++ b/usr.sbin/pkg_add/OpenBSD/Update.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Update.pm,v 1.4 2004/11/01 14:30:00 espie Exp $ +# $OpenBSD: Update.pm,v 1.5 2004/11/01 15:45:02 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -43,25 +43,17 @@ use File::Temp qw/tempfile/; sub extract { my ($self, $state) = @_; - my $fullname = $self->fullname(); - my $file=$state->{archive}->next(); - if ($file->{name} ne $self->{name}) { - Fatal "Error: archive does not match", $file->{name}, "!=", - $self->{name}, "\n"; - } - my $destdir = $state->{destdir}; + my $file = $self->prepare_to_extract($state); if (defined $self->{link} || defined $self->{symlink}) { $self->{tempname} = 1; return; } - my ($fh, $tempname) = tempfile(DIR => dirname($destdir.$fullname)); + my ($fh, $tempname) = tempfile(DIR => dirname($file->{destdir}.$file->{name})); print "extracting $tempname\n"; $file->{name} = $tempname; - $file->{cwd} = $self->{cwd}; - $file->{destdir} = $destdir; $file->create(); $self->{tempname} = $tempname; } |