@@ -58,7 +58,7 @@ require Exporter;
58
58
command_bidi_pipe command_close_bidi_pipe
59
59
version exec_path hash_object git_cmd_try
60
60
remote_refs
61
- temp_acquire temp_release temp_reset) ;
61
+ temp_acquire temp_release temp_reset temp_path ) ;
62
62
63
63
64
64
=head1 DESCRIPTION
@@ -937,7 +937,7 @@ sub _close_cat_blob {
937
937
938
938
{ # %TEMP_* Lexical Context
939
939
940
- my (%TEMP_LOCKS , %TEMP_FILES );
940
+ my (%TEMP_FILEMAP , %TEMP_FILES );
941
941
942
942
=item temp_acquire ( NAME )
943
943
@@ -965,7 +965,7 @@ sub temp_acquire {
965
965
966
966
my $temp_fd = _temp_cache($name );
967
967
968
- $TEMP_LOCKS {$temp_fd } = 1;
968
+ $TEMP_FILES {$temp_fd }{ locked } = 1;
969
969
$temp_fd ;
970
970
}
971
971
@@ -991,16 +991,16 @@ the same string.
991
991
sub temp_release {
992
992
my ($self , $temp_fd , $trunc ) = _maybe_self(@_ );
993
993
994
- if (ref ( $ temp_fd) ne ' File::Temp ' ) {
994
+ if (exists $TEMP_FILEMAP { $ temp_fd} ) {
995
995
$temp_fd = $TEMP_FILES {$temp_fd };
996
996
}
997
- unless ($TEMP_LOCKS {$temp_fd }) {
997
+ unless ($TEMP_FILES {$temp_fd }{ locked }) {
998
998
carp " Attempt to release temp file '" ,
999
999
$temp_fd , " ' that has not been locked" ;
1000
1000
}
1001
1001
temp_reset($temp_fd ) if $trunc and $temp_fd -> opened;
1002
1002
1003
- $TEMP_LOCKS {$temp_fd } = 0;
1003
+ $TEMP_FILES {$temp_fd }{ locked } = 0;
1004
1004
undef ;
1005
1005
}
1006
1006
@@ -1009,9 +1009,9 @@ sub _temp_cache {
1009
1009
1010
1010
_verify_require();
1011
1011
1012
- my $temp_fd = \$TEMP_FILES {$name };
1012
+ my $temp_fd = \$TEMP_FILEMAP {$name };
1013
1013
if (defined $$temp_fd and $$temp_fd -> opened) {
1014
- if ($TEMP_LOCKS {$$temp_fd }) {
1014
+ if ($TEMP_FILES {$$temp_fd }{ locked }) {
1015
1015
throw Error::Simple(" Temp file with moniker '" ,
1016
1016
$name , " ' already in use" );
1017
1017
}
@@ -1021,12 +1021,13 @@ sub _temp_cache {
1021
1021
carp " Temp file '" , $name ,
1022
1022
" ' was closed. Opening replacement." ;
1023
1023
}
1024
- $$temp_fd = File::Temp -> new(
1025
- TEMPLATE => ' Git_XXXXXX ' ,
1026
- DIR => File::Spec -> tmpdir
1024
+ my $fname ;
1025
+ ( $$temp_fd , $fname ) = File::Temp -> tempfile(
1026
+ ' Git_XXXXXX ' , UNLINK => 1
1027
1027
) or throw Error::Simple(" couldn't open new temp file" );
1028
1028
$$temp_fd -> autoflush;
1029
1029
binmode $$temp_fd ;
1030
+ $TEMP_FILES {$$temp_fd }{fname } = $fname ;
1030
1031
}
1031
1032
$$temp_fd ;
1032
1033
}
@@ -1053,8 +1054,25 @@ sub temp_reset {
1053
1054
or throw Error::Simple(" expected file position to be reset" );
1054
1055
}
1055
1056
1057
+ =item temp_path ( NAME )
1058
+
1059
+ =item temp_path ( FILEHANDLE )
1060
+
1061
+ Returns the filename associated with the given tempfile.
1062
+
1063
+ =cut
1064
+
1065
+ sub temp_path {
1066
+ my ($self , $temp_fd ) = _maybe_self(@_ );
1067
+
1068
+ if (exists $TEMP_FILEMAP {$temp_fd }) {
1069
+ $temp_fd = $TEMP_FILEMAP {$temp_fd };
1070
+ }
1071
+ $TEMP_FILES {$temp_fd }{fname };
1072
+ }
1073
+
1056
1074
sub END {
1057
- unlink values %TEMP_FILES if %TEMP_FILES ;
1075
+ unlink values %TEMP_FILEMAP if %TEMP_FILEMAP ;
1058
1076
}
1059
1077
1060
1078
} # %TEMP_* Lexical Context
0 commit comments