diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2008-12-11 15:43:20 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2008-12-11 15:43:20 +0000 |
commit | 64f9981f717e4751c1460c2149f28fdcaefb18d8 (patch) | |
tree | 660a9f0eb864d6825a8554dc1dafe39b79a931fd /usr.sbin/pkg_add/OpenBSD | |
parent | bea997a6c1b5d2bb12c1779c28c9ba3865d5baa8 (diff) |
copying local files may cause some issues, as noticed by sturm@
Try really hard to avoid copying a file on itself: by first checking the
stat() results, and if they are not available (since some people use fucked-up
stuff like AFS), rely on the file names as a last resort.
This should avoid stuff getting copied from PKG_CACHE to PKG_CACHE and
erasing itself in a few cases...
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository.pm | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm index d8fdcff5e21..ee9345b84e0 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageRepository.pm,v 1.60 2008/10/25 22:28:42 bernd Exp $ +# $OpenBSD: PackageRepository.pm,v 1.61 2008/12/11 15:43:19 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -280,11 +280,32 @@ sub parse_fullurl return $class->parse_local_url($r); } +# wrapper around copy, that sometimes does not copy +sub may_copy +{ + my ($self, $object, $destdir) = @_; + my $src = $self->relative_url($object->{name}); + require File::Spec; + my (undef, undef, $base) = File::Spec->splitpath($src); + my $dest = File::Spec->catfile($destdir, $base); + if (File::Spec->canonpath($dest) eq File::Spec->canonpath($src)) { + return; + } + if (-f $dest) { + my ($ddev, $dino) = (stat $dest)[0,1]; + my ($sdev, $sino) = (stat $src)[0, 1]; + if ($ddev == $sdev and $sino == $dino) { + return; + } + } + Copy($src, $destdir); +} + sub open_pipe { my ($self, $object) = @_; if (defined $ENV{'PKG_CACHE'}) { - Copy($self->relative_url($object->{name}), $ENV{'PKG_CACHE'}); + $self->may_copy($object, $ENV{'PKG_CACHE'}); } my $pid = open(my $fh, "-|"); if (!defined $pid) { |