summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2019-06-03 19:21:06 +0000
committerMarc Espie <espie@cvs.openbsd.org>2019-06-03 19:21:06 +0000
commite3eaed992c72446bf4deb5bf66c325616125f9eb (patch)
tree985bcc3bdfc2c9b436df7075e35e232a13037af5 /usr.sbin/pkg_add/OpenBSD
parentfcff8f3164088adcd21e0148050c1e53965fd6d8 (diff)
be better at finding a nice directory to extract temporary files
(this should interface with vstat to avoid vanishing directories, but it's already better than it was)
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Add.pm41
1 files changed, 26 insertions, 15 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm
index 5ccd91e607b..50077ef7527 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.179 2018/12/13 12:48:53 espie Exp $
+# $OpenBSD: Add.pm,v 1.180 2019/06/03 19:21:05 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -450,9 +450,32 @@ sub prepare_to_extract
$file->{destdir} = $destdir;
}
+sub find_safe_dir
+{
+ my ($self, $filename) = @_;
+ # figure out a safe directory where to put the temp file
+ my $d = dirname($filename);
+
+ # we go back up until we find an existing directory.
+ # hopefully this will be on the same file system.
+ my @candidates = ();
+ while (!-d $d) {
+ push(@candidates, $d);
+ $d = dirname($d);
+ }
+ # and now we try to go back down, creating the best path we can
+ while (@candidates > 0) {
+ my $c = pop @candidates;
+ last if -e $c; # okay this exists, but is not a directory
+ $d = $c;
+ }
+ return $d;
+}
+
sub create_temp
{
my ($self, $d, $state, $fullname) = @_;
+ # XXX this takes over right after find_safe_dir
if (!-e _) {
$state->make_path($d, $fullname);
}
@@ -477,13 +500,7 @@ sub tie
$self->SUPER::extract($state);
- # figure out a safe directory where to put the temp file
- my $d = dirname($state->{destdir}.$self->fullname);
- # we go back up until we find an existing directory.
- # hopefully this will be on the same file system.
- while (!-d $d && -e _) {
- $d = dirname($d);
- }
+ my $d = $self->find_safe_dir($state->{destdir}.$self->fullname);
if ($state->{not}) {
$state->say("link #1 -> #2",
$self->name, $d) if $state->verbose >= 3;
@@ -506,13 +523,7 @@ sub extract
$self->SUPER::extract($state);
- # figure out a safe directory where to put the temp file
- my $d = dirname($file->{destdir}.$file->name);
- # we go back up until we find an existing directory.
- # hopefully this will be on the same file system.
- while (!-d $d && -e _) {
- $d = dirname($d);
- }
+ my $d = $self->find_safe_dir($file->{destdir}.$file->name);
if ($state->{not}) {
$state->say("extract #1 -> #2",
$self->name, $d) if $state->verbose >= 3;