@@ -61,7 +61,7 @@ require Exporter;
61
61
remote_refs prompt
62
62
get_tz_offset
63
63
credential credential_read credential_write
64
- temp_acquire temp_release temp_reset temp_path) ;
64
+ temp_acquire temp_is_locked temp_release temp_reset temp_path) ;
65
65
66
66
67
67
=head1 DESCRIPTION
@@ -1206,6 +1206,35 @@ sub temp_acquire {
1206
1206
$temp_fd ;
1207
1207
}
1208
1208
1209
+ =item temp_is_locked ( NAME )
1210
+
1211
+ Returns true if the internal lock created by a previous C<temp_acquire() >
1212
+ call with C<NAME > is still in effect.
1213
+
1214
+ When temp_acquire is called on a C<NAME > , it internally locks the temporary
1215
+ file mapped to C<NAME > . That lock will not be released until C<temp_release() >
1216
+ is called with either the original C<NAME > or the L<File::Handle> that was
1217
+ returned from the original call to temp_acquire.
1218
+
1219
+ Subsequent attempts to call C<temp_acquire() > with the same C<NAME > will fail
1220
+ unless there has been an intervening C<temp_release() > call for that C<NAME >
1221
+ (or its corresponding L<File::Handle> that was returned by the original
1222
+ C<temp_acquire() > call).
1223
+
1224
+ If true is returned by C<temp_is_locked() > for a C<NAME > , an attempt to
1225
+ C<temp_acquire() > the same C<NAME > will cause an error unless
1226
+ C<temp_release > is first called on that C<NAME > (or its corresponding
1227
+ L<File::Handle> that was returned by the original C<temp_acquire() > call).
1228
+
1229
+ =cut
1230
+
1231
+ sub temp_is_locked {
1232
+ my ($self , $name ) = _maybe_self(@_ );
1233
+ my $temp_fd = \$TEMP_FILEMAP {$name };
1234
+
1235
+ defined $$temp_fd && $$temp_fd -> opened && $TEMP_FILES {$$temp_fd }{locked };
1236
+ }
1237
+
1209
1238
=item temp_release ( NAME )
1210
1239
1211
1240
=item temp_release ( FILEHANDLE )
@@ -1248,7 +1277,7 @@ sub _temp_cache {
1248
1277
1249
1278
my $temp_fd = \$TEMP_FILEMAP {$name };
1250
1279
if (defined $$temp_fd and $$temp_fd -> opened) {
1251
- if ($TEMP_FILES { $$temp_fd }{ locked } ) {
1280
+ if (temp_is_locked( $name ) ) {
1252
1281
throw Error::Simple(" Temp file with moniker '" .
1253
1282
$name . " ' already in use" );
1254
1283
}
0 commit comments