OpenSSL::Test: Fix directory calculations in __cwd()

We recalculate the location of the directories we keep track of.
However, we did so after having moved to the new directory already, so
the data we did the calculations from were possibly not quite correct.

This change moves the calculations to happen before moving to the new
directory.

This issue is sporadic, and possibly dependent on the platform.

Reviewed-by: Matt Caswell <matt@openssl.org>
This commit is contained in:
Richard Levitte 2016-06-20 14:03:12 +02:00
parent c952780c25
commit 3da9eeb158

View File

@ -821,12 +821,10 @@ sub __cwd {
mkpath($dir);
}
# Should we just bail out here as well? I'm unsure.
return undef unless chdir($dir);
if ($opts{cleanup}) {
rmtree(".", { safe => 0, keep_root => 1 });
}
# We are recalculating the directories we keep track of, but need to save
# away the result for after having moved into the new directory.
my %tmp_directories = ();
my %tmp_ENV = ();
# For each of these directory variables, figure out where they are relative
# to the directory we want to move to if they aren't absolute (if they are,
@ -835,7 +833,7 @@ sub __cwd {
foreach (@dirtags) {
if (!file_name_is_absolute($directories{$_})) {
my $newpath = abs2rel(rel2abs($directories{$_}), rel2abs($dir));
$directories{$_} = $newpath;
$tmp_directories{$_} = $newpath;
}
}
@ -845,10 +843,22 @@ sub __cwd {
foreach (@direnv) {
if (!file_name_is_absolute($ENV{$_})) {
my $newpath = abs2rel(rel2abs($ENV{$_}), rel2abs($dir));
$ENV{$_} = $newpath;
$tmp_ENV{$_} = $newpath;
}
}
# Should we just bail out here as well? I'm unsure.
return undef unless chdir($dir);
if ($opts{cleanup}) {
rmtree(".", { safe => 0, keep_root => 1 });
}
%directories = %tmp_directories;
foreach (keys %tmp_ENV) {
$ENV{$_} = $tmp_ENV{$_};
}
if ($debug) {
print STDERR "DEBUG: __cwd(), directories and files:\n";
print STDERR " \$directories{BLDTEST} = \"$directories{BLDTEST}\"\n";