| 1 |
Make File::Temp warn on cleaning up the current working directory at exit instead of bailing out. (Closes: #479317)
|
| 2 |
|
| 3 |
Adapted from File-Temp 0.21.
|
| 4 |
[rt.cpan.org #35779]
|
| 5 |
diff --git a/lib/File/Temp.pm b/lib/File/Temp.pm
|
| 6 |
index b933963..ccc2316 100644
|
| 7 |
--- a/lib/File/Temp.pm
|
| 8 |
+++ b/lib/File/Temp.pm
|
| 9 |
@@ -890,7 +890,12 @@ sub _can_do_level {
|
| 10 |
@{ $dirs_to_unlink{$$} } : () );
|
| 11 |
foreach my $dir (@dirs) {
|
| 12 |
if (-d $dir) {
|
| 13 |
- rmtree($dir, $DEBUG, 0);
|
| 14 |
+ # Some versions of rmtree will abort if you attempt to remove
|
| 15 |
+ # the directory you are sitting in. We protect that and turn it
|
| 16 |
+ # into a warning. We do this because this occurs during
|
| 17 |
+ # cleanup and so can not be caught by the user.
|
| 18 |
+ eval { rmtree($dir, $DEBUG, 0); };
|
| 19 |
+ warn $@ if ($@ && $^W);
|
| 20 |
}
|
| 21 |
}
|
| 22 |
|
| 23 |
@@ -2234,6 +2239,12 @@ srand(EXPR) in each child else all the children will attempt to walk
|
| 24 |
through the same set of random file names and may well cause
|
| 25 |
themselves to give up if they exceed the number of retry attempts.
|
| 26 |
|
| 27 |
+=head2 Directory removal
|
| 28 |
+
|
| 29 |
+Note that if you have chdir'ed into the temporary directory and it is
|
| 30 |
+subsequently cleaned up in the END block, then you will get a warning
|
| 31 |
+from File::Path::rmtree().
|
| 32 |
+
|
| 33 |
=head2 BINMODE
|
| 34 |
|
| 35 |
The file returned by File::Temp will have been opened in binary mode
|