From fc5341d7eef05e70a3756539c5ab1d8dbfe1362f Mon Sep 17 00:00:00 2001 From: Mark Vitale Date: Thu, 14 Mar 2024 00:06:51 -0400 Subject: [PATCH] tests: Cleanup auth/writeoldkey-t temp directory Commit cbc5c4b51fcd 'tests: Modernize writekeyfile.c' introduced writeoldkey-t and specified CLEANUP for its afs_XXXXX temporary work directory. However, Perl will not perform CLEANUP if the script is still in that directory at exit. Therefore writeoldkey-t leaves behind an afs_XXXXX temp directory for each run. Modify writeoldkey-t to cd back into 'tests' before exit, so that CLEANUP will work as intended. [mmeffie: save the cwd before cd to the temp dir] Change-Id: Ida723f9bfca05cc96acf189156d13c8607d210f4 Reviewed-on: https://gerrit.openafs.org/15724 Tested-by: BuildBot Reviewed-by: Mark Vitale Reviewed-by: Cheyenne Wills Reviewed-by: Michael Meffie --- tests/auth/writeoldkey-t | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/auth/writeoldkey-t b/tests/auth/writeoldkey-t index 614dcb6031..efb32a1d26 100755 --- a/tests/auth/writeoldkey-t +++ b/tests/auth/writeoldkey-t @@ -7,7 +7,7 @@ use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5"; use afstest qw(src_path obj_path); use Test::More; use File::Temp qw/tempdir/; -use Cwd qw/abs_path/; +use Cwd qw/abs_path getcwd/; use File::Compare; use Sys::Hostname; use Socket; @@ -27,6 +27,7 @@ $cmd = abs_path($cmd); my $keyfile = src_path("tests/auth/KeyFile.short"); $keyfile = abs_path($keyfile); +my $origdir = getcwd(); my $dir = tempdir('afs_XXXXXX', CLEANUP => 1); chdir($dir) @@ -37,3 +38,7 @@ system($cmd) == 0 ok(compare("KeyFile", $keyfile) == 0, "writekeyfile generates expected KeyFile"); + +# The cleanup handler needs to run in the original directory. +chdir($origdir) + or die("chdir $origdir failed: $?");