summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--testsuite/CuTmpdir.pm24
1 files changed, 13 insertions, 11 deletions
diff --git a/testsuite/CuTmpdir.pm b/testsuite/CuTmpdir.pm
index 166e50b..0af5d94 100644
--- a/testsuite/CuTmpdir.pm
+++ b/testsuite/CuTmpdir.pm
@@ -1,7 +1,7 @@
package CuTmpdir;
# create, then chdir into a temporary sub-directory
-# Copyright (C) 2007-2008 Free Software Foundation, Inc.
+# Copyright (C) 2007-2009 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -45,16 +45,13 @@ sub chmod_1
sub chmod_tree
{
- if (defined $dir && chdir $dir)
- {
- # Perform the equivalent of find . -type d -print0|xargs -0 chmod -R 700.
- my $options = {untaint => 1, wanted => \&chmod_1};
- find ($options, '.');
- }
- else
- {
- warn "$ME: failed to chdir to $dir: $!\n";
- }
+ # When tempdir fails, it croaks, which leaves $dir undefined.
+ defined $dir
+ or return;
+
+ # Perform the equivalent of find "$dir" -type d -print0|xargs -0 chmod -R 700.
+ my $options = {untaint => 1, wanted => \&chmod_1};
+ find ($options, $dir);
}
sub import {
@@ -101,6 +98,11 @@ sub import {
}
END {
+ # Move cwd out of the directory we're about to remove.
+ # This is required on some systems, and by some versions of File::Temp.
+ chdir '..'
+ or warn "$ME: failed to chdir to .. from $dir: $!\n";
+
my $saved_errno = $?;
chmod_tree;
$? = $saved_errno;