← Index
NYTProf Performance Profile   « line view »
For rbm/rbm
  Run on Wed Feb 12 20:36:06 2020
Reported on Wed Feb 12 21:42:25 2020

Filename/usr/share/perl/5.28/File/Temp.pm
StatementsExecuted 307424 statements in 1.43s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
458521404ms1.16sFile::Temp::::_gettemp File::Temp::_gettemp
458511256ms343msFile::Temp::::_replace_XX File::Temp::_replace_XX
458322252ms1.64sFile::Temp::::tempfile File::Temp::tempfile
458311222ms222msFile::Temp::::CORE:sysopen File::Temp::CORE:sysopen (opcode)
504261154.4ms54.4msFile::Temp::::CORE:substcont File::Temp::CORE:substcont (opcode)
45873138.0ms38.0msFile::Temp::::_parse_args File::Temp::_parse_args
45852132.9ms32.9msFile::Temp::::CORE:chmod File::Temp::CORE:chmod (opcode)
45851129.1ms29.1msFile::Temp::::CORE:ftis File::Temp::CORE:ftis (opcode)
45851122.8ms22.8msFile::Temp::::CORE:subst File::Temp::CORE:subst (opcode)
91701116.7ms16.7msFile::Temp::::safe_level File::Temp::safe_level
45851110.1ms10.1msFile::Temp::::CORE:regcomp File::Temp::CORE:regcomp (opcode)
4585116.17ms6.17msFile::Temp::::CORE:ftdir File::Temp::CORE:ftdir (opcode)
111722µs940µsFile::Temp::::BEGIN@16 File::Temp::BEGIN@16
111423µs525µsFile::Temp::::BEGIN@15 File::Temp::BEGIN@15
2511258µs361µsFile::Temp::::NUMIFY File::Temp::NUMIFY
211232µs232µsFile::Temp::::CORE:mkdir File::Temp::CORE:mkdir (opcode)
2732205µs205µsFile::Temp::Dir::::dirnameFile::Temp::Dir::dirname
222168µs981µsFile::Temp::::newdir File::Temp::newdir
111133µs105msFile::Temp::Dir::::DESTROYFile::Temp::Dir::DESTROY
21177µs750µsFile::Temp::::tempdir File::Temp::tempdir
11136µs38µsFile::Temp::::cleanup File::Temp::cleanup
11130µs69µsFile::Temp::::END File::Temp::END
11119µs27µsFile::Temp::::BEGIN@11 File::Temp::BEGIN@11
11118µs18µsFile::Temp::::BEGIN@8 File::Temp::BEGIN@8
11117µs29µsFile::Temp::::BEGIN@43 File::Temp::BEGIN@43
11115µs260µsFile::Temp::::BEGIN@14 File::Temp::BEGIN@14
11115µs51µsFile::Temp::::BEGIN@13 File::Temp::BEGIN@13
11115µs54µsFile::Temp::::BEGIN@31 File::Temp::BEGIN@31
11114µs79µsFile::Temp::Dir::::BEGIN@1541File::Temp::Dir::BEGIN@1541
11113µs13µsFile::Temp::Dir::::CORE:ftdirFile::Temp::Dir::CORE:ftdir (opcode)
11112µs20µsFile::Temp::::BEGIN@137 File::Temp::BEGIN@137
11110µs54µsFile::Temp::Dir::::BEGIN@1543File::Temp::Dir::BEGIN@1543
11110µs70µsFile::Temp::::BEGIN@83 File::Temp::BEGIN@83
1119µs47µsFile::Temp::::BEGIN@32 File::Temp::BEGIN@32
1119µs28µsFile::Temp::::BEGIN@17 File::Temp::BEGIN@17
1119µs14µsFile::Temp::Dir::::BEGIN@1542File::Temp::Dir::BEGIN@1542
1117µs7µsFile::Temp::Dir::::unlink_on_destroyFile::Temp::Dir::unlink_on_destroy
2117µs7µsFile::Temp::::CORE:match File::Temp::CORE:match (opcode)
1116µs9µsFile::Temp::::BEGIN@9 File::Temp::BEGIN@9
1116µs23µsFile::Temp::::BEGIN@107 File::Temp::BEGIN@107
1116µs86µsFile::Temp::::BEGIN@86 File::Temp::BEGIN@86
1115µs53µsFile::Temp::::BEGIN@36 File::Temp::BEGIN@36
1115µs28µsFile::Temp::::BEGIN@90 File::Temp::BEGIN@90
1115µs35µsFile::Temp::::BEGIN@10 File::Temp::BEGIN@10
1115µs25µsFile::Temp::::BEGIN@94 File::Temp::BEGIN@94
1115µs25µsFile::Temp::::BEGIN@96 File::Temp::BEGIN@96
1114µs26µsFile::Temp::::BEGIN@95 File::Temp::BEGIN@95
1113µs3µsFile::Temp::::BEGIN@12 File::Temp::BEGIN@12
1112µs2µsFile::Temp::::CORE:sort File::Temp::CORE:sort (opcode)
111800ns800nsFile::Temp::::__ANON__[:111] File::Temp::__ANON__[:111]
111700ns700nsFile::Temp::::__ANON__[:119] File::Temp::__ANON__[:119]
111600ns600nsFile::Temp::::__ANON__ File::Temp::__ANON__ (xsub)
111500ns500nsFile::Temp::::__ANON__[:141] File::Temp::__ANON__[:141]
0000s0sFile::Temp::::DESTROY File::Temp::DESTROY
0000s0sFile::Temp::Dir::::STRINGIFYFile::Temp::Dir::STRINGIFY
0000s0sFile::Temp::::STRINGIFY File::Temp::STRINGIFY
0000s0sFile::Temp::::__ANON__[:112] File::Temp::__ANON__[:112]
0000s0sFile::Temp::::__ANON__[:120] File::Temp::__ANON__[:120]
0000s0sFile::Temp::::__ANON__[:142] File::Temp::__ANON__[:142]
0000s0sFile::Temp::::_can_do_level File::Temp::_can_do_level
0000s0sFile::Temp::::_can_unlink_opened_file File::Temp::_can_unlink_opened_file
0000s0sFile::Temp::::_deferred_unlink File::Temp::_deferred_unlink
0000s0sFile::Temp::::_force_writable File::Temp::_force_writable
0000s0sFile::Temp::::_is_safe File::Temp::_is_safe
0000s0sFile::Temp::::_is_verysafe File::Temp::_is_verysafe
0000s0sFile::Temp::::cmpstat File::Temp::cmpstat
0000s0sFile::Temp::::filename File::Temp::filename
0000s0sFile::Temp::::mkdtemp File::Temp::mkdtemp
0000s0sFile::Temp::::mkstemp File::Temp::mkstemp
0000s0sFile::Temp::::mkstemps File::Temp::mkstemps
0000s0sFile::Temp::::mktemp File::Temp::mktemp
0000s0sFile::Temp::::new File::Temp::new
0000s0sFile::Temp::::tempnam File::Temp::tempnam
0000s0sFile::Temp::::tmpfile File::Temp::tmpfile
0000s0sFile::Temp::::tmpnam File::Temp::tmpnam
0000s0sFile::Temp::::top_system_uid File::Temp::top_system_uid
0000s0sFile::Temp::::unlink0 File::Temp::unlink0
0000s0sFile::Temp::::unlink1 File::Temp::unlink1
0000s0sFile::Temp::::unlink_on_destroy File::Temp::unlink_on_destroy
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package File::Temp;
2# ABSTRACT: return name and handle of a temporary file safely
31500nsour $VERSION = '0.2304'; # VERSION
4
5# Toolchain targets v5.8.1, but we'll try to support back to v5.6 anyway.
6# It might be possible to make this v5.5, but many v5.6isms are creeping
7# into the code and tests.
8246µs118µs
# spent 18µs within File::Temp::BEGIN@8 which was called: # once (18µs+0s) by IO::CaptureOutput::_proxy::BEGIN@138 at line 8
use 5.006;
# spent 18µs making 1 call to File::Temp::BEGIN@8
9218µs211µs
# spent 9µs (6+2) within File::Temp::BEGIN@9 which was called: # once (6µs+2µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 9
use strict;
# spent 9µs making 1 call to File::Temp::BEGIN@9 # spent 2µs making 1 call to strict::import
10222µs264µs
# spent 35µs (5+30) within File::Temp::BEGIN@10 which was called: # once (5µs+30µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 10
use Carp;
# spent 35µs making 1 call to File::Temp::BEGIN@10 # spent 30µs making 1 call to Exporter::import
11343µs335µs
# spent 27µs (19+8) within File::Temp::BEGIN@11 which was called: # once (19µs+8µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 11
use File::Spec 0.8;
# spent 27µs making 1 call to File::Temp::BEGIN@11 # spent 7µs making 1 call to UNIVERSAL::VERSION # spent 600ns making 1 call to File::Temp::__ANON__
12220µs13µs
# spent 3µs within File::Temp::BEGIN@12 which was called: # once (3µs+0s) by IO::CaptureOutput::_proxy::BEGIN@138 at line 12
use Cwd ();
# spent 3µs making 1 call to File::Temp::BEGIN@12
13339µs387µs
# spent 51µs (15+36) within File::Temp::BEGIN@13 which was called: # once (15µs+36µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 13
use File::Path 2.06 qw/ rmtree /;
# spent 51µs making 1 call to File::Temp::BEGIN@13 # spent 31µs making 1 call to Exporter::import # spent 5µs making 1 call to UNIVERSAL::VERSION
14338µs3505µs
# spent 260µs (15+245) within File::Temp::BEGIN@14 which was called: # once (15µs+245µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 14
use Fcntl 1.03;
# spent 260µs making 1 call to File::Temp::BEGIN@14 # spent 240µs making 1 call to Exporter::import # spent 5µs making 1 call to UNIVERSAL::VERSION
15291µs2549µs
# spent 525µs (423+102) within File::Temp::BEGIN@15 which was called: # once (423µs+102µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 15
use IO::Seekable; # For SEEK_*
# spent 525µs making 1 call to File::Temp::BEGIN@15 # spent 24µs making 1 call to Exporter::import
162109µs2954µs
# spent 940µs (722+218) within File::Temp::BEGIN@16 which was called: # once (722µs+218µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 16
use Errno;
# spent 940µs making 1 call to File::Temp::BEGIN@16 # spent 14µs making 1 call to Exporter::import
17260µs246µs
# spent 28µs (9+19) within File::Temp::BEGIN@17 which was called: # once (9µs+19µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 17
use Scalar::Util 'refaddr';
# spent 28µs making 1 call to File::Temp::BEGIN@17 # spent 19µs making 1 call to Exporter::import
1812µsrequire VMS::Stdio if $^O eq 'VMS';
19
20# pre-emptively load Carp::Heavy. If we don't when we run out of file
21# handles and attempt to call croak() we get an error message telling
22# us that Carp::Heavy won't load rather than an error telling us we
23# have run out of file handles. We either preload croak() or we
24# switch the calls to croak from _gettemp() to use die.
252112µseval { require Carp::Heavy; };
26
27# Need the Symbol package if we are running older perl
281600nsrequire Symbol if $] < 5.006;
29
30### For the OO interface
31350µs394µs
# spent 54µs (15+40) within File::Temp::BEGIN@31 which was called: # once (15µs+40µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 31
use parent 0.221 qw/ IO::Handle IO::Seekable /;
# spent 54µs making 1 call to File::Temp::BEGIN@31 # spent 30µs making 1 call to parent::import # spent 9µs making 1 call to UNIVERSAL::VERSION
3218µs138µs
# spent 47µs (9+38) within File::Temp::BEGIN@32 which was called: # once (9µs+38µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 33
use overload '""' => "STRINGIFY", '0+' => "NUMIFY",
# spent 38µs making 1 call to overload::import
33123µs147µs fallback => 1;
# spent 47µs making 1 call to File::Temp::BEGIN@32
34
35# use 'our' on v5.6.0
36235µs2101µs
# spent 53µs (5+48) within File::Temp::BEGIN@36 which was called: # once (5µs+48µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 36
use vars qw(@EXPORT_OK %EXPORT_TAGS $DEBUG $KEEP_ALL);
# spent 53µs making 1 call to File::Temp::BEGIN@36 # spent 48µs making 1 call to vars::import
37
381400ns$DEBUG = 0;
391100ns$KEEP_ALL = 0;
40
41# We are exporting functions
42
433102µs341µs
# spent 29µs (17+12) within File::Temp::BEGIN@43 which was called: # once (17µs+12µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 43
use Exporter 5.57 'import'; # 5.57 lets us import 'import'
# spent 29µs making 1 call to File::Temp::BEGIN@43 # spent 6µs making 1 call to Exporter::import # spent 6µs making 1 call to UNIVERSAL::VERSION
44
45# Export list - to allow fine tuning of export table
46
4713µs@EXPORT_OK = qw{
48 tempfile
49 tempdir
50 tmpnam
51 tmpfile
52 mktemp
53 mkstemp
54 mkstemps
55 mkdtemp
56 unlink0
57 cleanup
58 SEEK_SET
59 SEEK_CUR
60 SEEK_END
61 };
62
63# Groups of functions for export
64
6514µs%EXPORT_TAGS = (
66 'POSIX' => [qw/ tmpnam tmpfile /],
67 'mktemp' => [qw/ mktemp mkstemp mkstemps mkdtemp/],
68 'seekable' => [qw/ SEEK_SET SEEK_CUR SEEK_END /],
69 );
70
71# add contents of these tags to @EXPORT
7213µs132µsExporter::export_tags('POSIX','mktemp','seekable');
# spent 32µs making 1 call to Exporter::export_tags
73
74# This is a list of characters that can be used in random filenames
75
7615µsmy @CHARS = (qw/ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
77 a b c d e f g h i j k l m n o p q r s t u v w x y z
78 0 1 2 3 4 5 6 7 8 9 _
79 /);
80
81# Maximum number of tries to make a temp file before failing
82
83229µs2130µs
# spent 70µs (10+60) within File::Temp::BEGIN@83 which was called: # once (10µs+60µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 83
use constant MAX_TRIES => 1000;
# spent 70µs making 1 call to File::Temp::BEGIN@83 # spent 60µs making 1 call to constant::import
84
85# Minimum number of X characters that should be in a template
86228µs2166µs
# spent 86µs (6+80) within File::Temp::BEGIN@86 which was called: # once (6µs+80µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 86
use constant MINX => 4;
# spent 86µs making 1 call to File::Temp::BEGIN@86 # spent 80µs making 1 call to constant::import
87
88# Default template when no template supplied
89
90226µs252µs
# spent 28µs (5+23) within File::Temp::BEGIN@90 which was called: # once (5µs+23µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 90
use constant TEMPXXX => 'X' x 10;
# spent 28µs making 1 call to File::Temp::BEGIN@90 # spent 23µs making 1 call to constant::import
91
92# Constants for the security level
93
94226µs246µs
# spent 25µs (5+20) within File::Temp::BEGIN@94 which was called: # once (5µs+20µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 94
use constant STANDARD => 0;
# spent 25µs making 1 call to File::Temp::BEGIN@94 # spent 20µs making 1 call to constant::import
95220µs248µs
# spent 26µs (4+22) within File::Temp::BEGIN@95 which was called: # once (4µs+22µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 95
use constant MEDIUM => 1;
# spent 26µs making 1 call to File::Temp::BEGIN@95 # spent 22µs making 1 call to constant::import
96258µs245µs
# spent 25µs (5+20) within File::Temp::BEGIN@96 which was called: # once (5µs+20µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 96
use constant HIGH => 2;
# spent 25µs making 1 call to File::Temp::BEGIN@96 # spent 20µs making 1 call to constant::import
97
98# OPENFLAGS. If we defined the flag to use with Sysopen here this gives
99# us an optimisation when many temporary files are requested
100
1011200nsmy $OPENFLAGS = O_CREAT | O_EXCL | O_RDWR;
1021200nsmy $LOCKFLAG;
103
10411µsunless ($^O eq 'MacOS') {
1051300ns for my $oflag (qw/ NOFOLLOW BINARY LARGEFILE NOINHERIT /) {
10642µs my ($bit, $func) = (0, "Fcntl::O_" . $oflag);
1072176µs239µs
# spent 23µs (6+16) within File::Temp::BEGIN@107 which was called: # once (6µs+16µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 107
no strict 'refs';
# spent 23µs making 1 call to File::Temp::BEGIN@107 # spent 16µs making 1 call to strict::unimport
10843µs $OPENFLAGS |= $bit if eval {
109 # Make sure that redefined die handlers do not cause problems
110 # e.g. CGI::Carp
111512µs
# spent 800ns within File::Temp::__ANON__[/usr/share/perl/5.28/File/Temp.pm:111] which was called: # once (800ns+0s) by Fcntl::O_NOINHERIT at line 113
local $SIG{__DIE__} = sub {};
11246µs local $SIG{__WARN__} = sub {};
113462µs547µs $bit = &$func();
# spent 33µs making 1 call to Fcntl::O_NOINHERIT # spent 6µs making 1 call to Fcntl::O_NOFOLLOW # spent 4µs making 1 call to Fcntl::O_BINARY # spent 3µs making 1 call to Fcntl::O_LARGEFILE # spent 800ns making 1 call to File::Temp::__ANON__[File/Temp.pm:111]
11437µs 1;
115 };
116 }
117 # Special case O_EXLOCK
1181300ns $LOCKFLAG = eval {
11925µs
# spent 700ns within File::Temp::__ANON__[/usr/share/perl/5.28/File/Temp.pm:119] which was called: # once (700ns+0s) by Fcntl::O_EXLOCK at line 121
local $SIG{__DIE__} = sub {};
12012µs local $SIG{__WARN__} = sub {};
121115µs214µs &Fcntl::O_EXLOCK();
# spent 13µs making 1 call to Fcntl::O_EXLOCK # spent 700ns making 1 call to File::Temp::__ANON__[File/Temp.pm:119]
122 };
123}
124
125# On some systems the O_TEMPORARY flag can be used to tell the OS
126# to automatically remove the file when it is closed. This is fine
127# in most cases but not if tempfile is called with UNLINK=>0 and
128# the filename is requested -- in the case where the filename is to
129# be passed to another routine. This happens on windows. We overcome
130# this by using a second open flags variable
131
1321200nsmy $OPENTEMPFLAGS = $OPENFLAGS;
1331600nsunless ($^O eq 'MacOS') {
1341300ns for my $oflag (qw/ TEMPORARY /) {
1351700ns my ($bit, $func) = (0, "Fcntl::O_" . $oflag);
1361200ns local($@);
1372682µs227µs
# spent 20µs (12+7) within File::Temp::BEGIN@137 which was called: # once (12µs+7µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 137
no strict 'refs';
# spent 20µs making 1 call to File::Temp::BEGIN@137 # spent 7µs making 1 call to strict::unimport
1381300ns $OPENTEMPFLAGS |= $bit if eval {
139 # Make sure that redefined die handlers do not cause problems
140 # e.g. CGI::Carp
14124µs
# spent 500ns within File::Temp::__ANON__[/usr/share/perl/5.28/File/Temp.pm:141] which was called: # once (500ns+0s) by Fcntl::O_TEMPORARY at line 143
local $SIG{__DIE__} = sub {};
14212µs local $SIG{__WARN__} = sub {};
143114µs213µs $bit = &$func();
# spent 12µs making 1 call to Fcntl::O_TEMPORARY # spent 500ns making 1 call to File::Temp::__ANON__[File/Temp.pm:141]
144 1;
145 };
146 }
147}
148
149# Private hash tracking which files have been created by each process id via the OO interface
1501100nsmy %FILES_CREATED_BY_OBJECT;
151
152# INTERNAL ROUTINES - not to be used outside of package
153
154# Generic routine for getting a temporary filename
155# modelled on OpenBSD _gettemp() in mktemp.c
156
157# The template must contain X's that are to be replaced
158# with the random values
159
160# Arguments:
161
162# TEMPLATE - string containing the XXXXX's that is converted
163# to a random filename and opened if required
164
165# Optionally, a hash can also be supplied containing specific options
166# "open" => if true open the temp file, else just return the name
167# default is 0
168# "mkdir"=> if true, we are creating a temp directory rather than tempfile
169# default is 0
170# "suffixlen" => number of characters at end of PATH to be ignored.
171# default is 0.
172# "unlink_on_close" => indicates that, if possible, the OS should remove
173# the file as soon as it is closed. Usually indicates
174# use of the O_TEMPORARY flag to sysopen.
175# Usually irrelevant on unix
176# "use_exlock" => Indicates that O_EXLOCK should be used. Default is true.
177
178# Optionally a reference to a scalar can be passed into the function
179# On error this will be used to store the reason for the error
180# "ErrStr" => \$errstr
181
182# "open" and "mkdir" can not both be true
183# "unlink_on_close" is not used when "mkdir" is true.
184
185# The default options are equivalent to mktemp().
186
187# Returns:
188# filehandle - open file handle (if called with doopen=1, else undef)
189# temp name - name of the temp file or directory
190
191# For example:
192# ($fh, $name) = _gettemp($template, "open" => 1);
193
194# for the current version, failures are associated with
195# stored in an error string and returned to give the reason whilst debugging
196# This routine is not called by any external function
197
# spent 1.16s (404ms+755ms) within File::Temp::_gettemp which was called 4585 times, avg 253µs/call: # 4583 times (404ms+755ms) by File::Temp::tempfile at line 1088, avg 253µs/call # 2 times (181µs+461µs) by File::Temp::tempdir at line 1201, avg 321µs/call
sub _gettemp {
198
19945853.38ms croak 'Usage: ($fh, $name) = _gettemp($template, OPTIONS);'
200 unless scalar(@_) >= 1;
201
202 # the internal error string - expect it to be overridden
203 # Need this in case the caller decides not to supply us a value
204 # need an anonymous scalar
2054585898µs my $tempErrStr;
206
207 # Default options
208458519.6ms my %options = (
209 "open" => 0,
210 "mkdir" => 0,
211 "suffixlen" => 0,
212 "unlink_on_close" => 0,
213 "use_exlock" => 1,
214 "ErrStr" => \$tempErrStr,
215 );
216
217 # Read the template
21845852.25ms my $template = shift;
21945851.78ms if (ref($template)) {
220 # Use a warning here since we have not yet merged ErrStr
221 carp "File::Temp::_gettemp: template must not be a reference";
222 return ();
223 }
224
225 # Check that the number of entries on stack are even
22645853.41ms if (scalar(@_) % 2 != 0) {
227 # Use a warning here since we have not yet merged ErrStr
228 carp "File::Temp::_gettemp: Must have even number of options";
229 return ();
230 }
231
232 # Read the options and merge with defaults
233458521.0ms %options = (%options, @_) if @_;
234
235 # Make sure the error string is set to undef
23645854.45ms ${$options{ErrStr}} = undef;
237
238 # Can not open the file and make a directory in a single call
23945853.52ms if ($options{"open"} && $options{"mkdir"}) {
240 ${$options{ErrStr}} = "doopen and domkdir can not both be true\n";
241 return ();
242 }
243
244 # Find the start of the end of the Xs (position of last X)
245 # Substr starts from 0
24645854.56ms my $start = length($template) - 1 - $options{"suffixlen"};
247
248 # Check that we have at least MINX x X (e.g. 'XXXX") at the end of the string
249 # (taking suffixlen into account). Any fewer is insecure.
250
251 # Do it using substr - no reason to use a pattern match since
252 # we know where we are looking and what we are looking for
253
25445856.94ms if (substr($template, $start - MINX + 1, MINX) ne 'X' x MINX) {
255 ${$options{ErrStr}} = "The template must end with at least ".
256 MINX . " 'X' characters\n";
257 return ();
258 }
259
260 # Replace all the X at the end of the substring with a
261 # random character or just all the XX at the end of a full string.
262 # Do it as an if, since the suffix adjusts which section to replace
263 # and suffixlen=0 returns nothing if used in the substr directly
264 # and generate a full path from the template
265
266458510.2ms4585343ms my $path = _replace_XX($template, $options{"suffixlen"});
# spent 343ms making 4585 calls to File::Temp::_replace_XX, avg 75µs/call
267
268 # Split the path into constituent parts - eventually we need to check
269 # whether the directory exists
270 # We need to know whether we are making a temp directory
271 # or a tempfile
272
27345851.55ms my ($volume, $directories, $file);
274 my $parent; # parent directory
27545852.89ms if ($options{"mkdir"}) {
276 # There is no filename at the end
277217µs28µs ($volume, $directories, $file) = File::Spec->splitpath( $path, 1);
# spent 8µs making 2 calls to File::Spec::Unix::splitpath, avg 4µs/call
278
279 # The parent is then $directories without the last directory
280 # Split the directory and put it back together again
28126µs25µs my @dirs = File::Spec->splitdir($directories);
# spent 5µs making 2 calls to File::Spec::Unix::splitdir, avg 3µs/call
282
283 # If @dirs only has one entry (i.e. the directory template) that means
284 # we are in the current directory
28523µs if ($#dirs == 0) {
286 $parent = File::Spec->curdir;
287 } else {
288
28922µs if ($^O eq 'VMS') { # need volume to avoid relative dir spec
290 $parent = File::Spec->catdir($volume, @dirs[0..$#dirs-1]);
291 $parent = 'sys$disk:[]' if $parent eq '';
292 } else {
293
294 # Put it back together without the last one
295243µs440µs $parent = File::Spec->catdir(@dirs[0..$#dirs-1]);
# spent 30µs making 2 calls to File::Spec::Unix::catdir, avg 15µs/call # spent 10µs making 2 calls to File::Spec::Unix::canonpath, avg 5µs/call
296
297 # ...and attach the volume (no filename)
29826µs29µs $parent = File::Spec->catpath($volume, $parent, '');
# spent 9µs making 2 calls to File::Spec::Unix::catpath, avg 5µs/call
299 }
300
301 }
302
303 } else {
304
305 # Get rid of the last filename (use File::Basename for this?)
306458317.3ms458384.4ms ($volume, $directories, $file) = File::Spec->splitpath( $path );
# spent 84.4ms making 4583 calls to File::Spec::Unix::splitpath, avg 18µs/call
307
308 # Join up without the file part
309458313.8ms458320.6ms $parent = File::Spec->catpath($volume,$directories,'');
# spent 20.6ms making 4583 calls to File::Spec::Unix::catpath, avg 4µs/call
310
311 # If $parent is empty replace with curdir
31245832.61ms $parent = File::Spec->curdir
313 unless $directories ne '';
314
315 }
316
317 # Check that the parent directories exist
318 # Do this even for the case where we are simply returning a name
319 # not a file -- no point returning a name that includes a directory
320 # that does not exist or is not writable
321
322458553.3ms458529.1ms unless (-e $parent) {
# spent 29.1ms making 4585 calls to File::Temp::CORE:ftis, avg 6µs/call
323 ${$options{ErrStr}} = "Parent directory ($parent) does not exist";
324 return ();
325 }
326458518.9ms45856.17ms unless (-d $parent) {
# spent 6.17ms making 4585 calls to File::Temp::CORE:ftdir, avg 1µs/call
327 ${$options{ErrStr}} = "Parent directory ($parent) is not a directory";
328 return ();
329 }
330
331 # Check the stickiness of the directory and chown giveaway if required
332 # If the directory is world writable the sticky bit
333 # must be set
334
335458529.5ms917016.7ms if (File::Temp->safe_level == MEDIUM) {
# spent 16.7ms making 9170 calls to File::Temp::safe_level, avg 2µs/call
336 my $safeerr;
337 unless (_is_safe($parent,\$safeerr)) {
338 ${$options{ErrStr}} = "Parent directory ($parent) is not safe ($safeerr)";
339 return ();
340 }
341 } elsif (File::Temp->safe_level == HIGH) {
342 my $safeerr;
343 unless (_is_verysafe($parent, \$safeerr)) {
344 ${$options{ErrStr}} = "Parent directory ($parent) is not safe ($safeerr)";
345 return ();
346 }
347 }
348
349 # Now try MAX_TRIES time to open the file
35045856.36ms for (my $i = 0; $i < MAX_TRIES; $i++) {
351
352 # Try to open the file if requested
35345851.73ms if ($options{"open"}) {
3544583836µs my $fh;
355
356 # If we are running before perl5.6.0 we can not auto-vivify
35745831.75ms if ($] < 5.006) {
358 $fh = &Symbol::gensym;
359 }
360
361 # Try to make sure this will be marked close-on-exec
362 # XXX: Win32 doesn't respect this, nor the proper fcntl,
363 # but may have O_NOINHERIT. This may or may not be in Fcntl.
36445838.01ms local $^F = 2;
365
366 # Attempt to open the file
36745831.63ms my $open_success = undef;
36845836.71ms if ( $^O eq 'VMS' and $options{"unlink_on_close"} && !$KEEP_ALL) {
369 # make it auto delete on close by setting FAB$V_DLT bit
370 $fh = VMS::Stdio::vmssysopen($path, $OPENFLAGS, 0600, 'fop=dlt');
371 $open_success = $fh;
372 } else {
37345834.23ms my $flags = ( ($options{"unlink_on_close"} && !$KEEP_ALL) ?
374 $OPENTEMPFLAGS :
375 $OPENFLAGS );
37645832.21ms $flags |= $LOCKFLAG if (defined $LOCKFLAG && $options{use_exlock});
3774583265ms4583222ms $open_success = sysopen($fh, $path, $flags, 0600);
# spent 222ms making 4583 calls to File::Temp::CORE:sysopen, avg 48µs/call
378 }
37945831.83ms if ( $open_success ) {
380
381 # in case of odd umask force rw
382458377.0ms458332.9ms chmod(0600, $path);
# spent 32.9ms making 4583 calls to File::Temp::CORE:chmod, avg 7µs/call
383
384 # Opened successfully - return file handle and name
385458322.6ms return ($fh, $path);
386
387 } else {
388
389 # Error opening file - abort with error
390 # if the reason was anything but EEXIST
39114.29ms111µs unless ($!{EEXIST}) {
# spent 11µs making 1 call to Errno::_tie_it
392 ${$options{ErrStr}} = "Could not create temp file $path: $!";
393 return ();
394 }
395
396 # Loop round for another try
397
398 }
399 } elsif ($options{"mkdir"}) {
400
401 # Open the temp directory
4022245µs2232µs if (mkdir( $path, 0700)) {
# spent 232µs making 2 calls to File::Temp::CORE:mkdir, avg 116µs/call
403 # in case of odd umask
404225µs217µs chmod(0700, $path);
# spent 17µs making 2 calls to File::Temp::CORE:chmod, avg 9µs/call
405
406210µs return undef, $path;
407 } else {
408
409 # Abort with error if the reason for failure was anything
410 # except EEXIST
411 unless ($!{EEXIST}) {
412 ${$options{ErrStr}} = "Could not create directory $path: $!";
413 return ();
414 }
415
416 # Loop round for another try
417
418 }
419
420 } else {
421
422 # Return true if the file can not be found
423 # Directory has been checked previously
424
425 return (undef, $path) unless -e $path;
426
427 # Try again until MAX_TRIES
428
429 }
430
431 # Did not successfully open the tempfile/dir
432 # so try again with a different set of random letters
433 # No point in trying to increment unless we have only
434 # 1 X say and the randomness could come up with the same
435 # file MAX_TRIES in a row.
436
437 # Store current attempt - in principal this implies that the
438 # 3rd time around the open attempt that the first temp file
439 # name could be generated again. Probably should store each
440 # attempt and make sure that none are repeated
441
442 my $original = $path;
443 my $counter = 0; # Stop infinite loop
444 my $MAX_GUESS = 50;
445
446 do {
447
448 # Generate new name from original template
449 $path = _replace_XX($template, $options{"suffixlen"});
450
451 $counter++;
452
453 } until ($path ne $original || $counter > $MAX_GUESS);
454
455 # Check for out of control looping
456 if ($counter > $MAX_GUESS) {
457 ${$options{ErrStr}} = "Tried to get a new temp name different to the previous value $MAX_GUESS times.\nSomething wrong with template?? ($template)";
458 return ();
459 }
460
461 }
462
463 # If we get here, we have run out of tries
464 ${ $options{ErrStr} } = "Have exceeded the maximum number of attempts ("
465 . MAX_TRIES . ") to open temp file/dir";
466
467 return ();
468
469}
470
471# Internal routine to replace the XXXX... with random characters
472# This has to be done by _gettemp() every time it fails to
473# open a temp file/dir
474
475# Arguments: $template (the template with XXX),
476# $ignore (number of characters at end to ignore)
477
478# Returns: modified template
479
480
# spent 343ms (256+87.3) within File::Temp::_replace_XX which was called 4585 times, avg 75µs/call: # 4585 times (256ms+87.3ms) by File::Temp::_gettemp at line 266, avg 75µs/call
sub _replace_XX {
481
48245853.49ms croak 'Usage: _replace_XX($template, $ignore)'
483 unless scalar(@_) == 2;
484
48545852.47ms my ($path, $ignore) = @_;
486
487 # Do it as an if, since the suffix adjusts which section to replace
488 # and suffixlen=0 returns nothing if used in the substr directly
489 # Alternatively, could simply set $ignore to length($path)-1
490 # Don't want to always use substr when not required though.
49145855.10ms my $end = ( $] >= 5.006 ? "\\z" : "\\Z" );
492
49345853.91ms if ($ignore) {
494 substr($path, 0, - $ignore) =~ s/X(?=X*$end)/$CHARS[ int( rand( @CHARS ) ) ]/ge;
495 } else {
4964585318ms5959687.3ms $path =~ s/X(?=X*$end)/$CHARS[ int( rand( @CHARS ) ) ]/ge;
# spent 54.4ms making 50426 calls to File::Temp::CORE:substcont, avg 1µs/call # spent 22.8ms making 4585 calls to File::Temp::CORE:subst, avg 5µs/call # spent 10.1ms making 4585 calls to File::Temp::CORE:regcomp, avg 2µs/call
497 }
498458529.5ms return $path;
499}
500
501# Internal routine to force a temp file to be writable after
502# it is created so that we can unlink it. Windows seems to occasionally
503# force a file to be readonly when written to certain temp locations
504sub _force_writable {
505 my $file = shift;
506 chmod 0600, $file;
507}
508
509# internal routine to check to see if the directory is safe
510# First checks to see if the directory is not owned by the
511# current user or root. Then checks to see if anyone else
512# can write to the directory and if so, checks to see if
513# it has the sticky bit set
514
515# Will not work on systems that do not support sticky bit
516
517#Args: directory path to check
518# Optionally: reference to scalar to contain error message
519# Returns true if the path is safe and false otherwise.
520# Returns undef if can not even run stat() on the path
521
522# This routine based on version written by Tom Christiansen
523
524# Presumably, by the time we actually attempt to create the
525# file or directory in this directory, it may not be safe
526# anymore... Have to run _is_safe directly after the open.
527
528sub _is_safe {
529
530 my $path = shift;
531 my $err_ref = shift;
532
533 # Stat path
534 my @info = stat($path);
535 unless (scalar(@info)) {
536 $$err_ref = "stat(path) returned no values";
537 return 0;
538 }
539 ;
540 return 1 if $^O eq 'VMS'; # owner delete control at file level
541
542 # Check to see whether owner is neither superuser (or a system uid) nor me
543 # Use the effective uid from the $> variable
544 # UID is in [4]
545 if ($info[4] > File::Temp->top_system_uid() && $info[4] != $>) {
546
547 Carp::cluck(sprintf "uid=$info[4] topuid=%s euid=$> path='$path'",
548 File::Temp->top_system_uid());
549
550 $$err_ref = "Directory owned neither by root nor the current user"
551 if ref($err_ref);
552 return 0;
553 }
554
555 # check whether group or other can write file
556 # use 066 to detect either reading or writing
557 # use 022 to check writability
558 # Do it with S_IWOTH and S_IWGRP for portability (maybe)
559 # mode is in info[2]
560 if (($info[2] & &Fcntl::S_IWGRP) || # Is group writable?
561 ($info[2] & &Fcntl::S_IWOTH) ) { # Is world writable?
562 # Must be a directory
563 unless (-d $path) {
564 $$err_ref = "Path ($path) is not a directory"
565 if ref($err_ref);
566 return 0;
567 }
568 # Must have sticky bit set
569 unless (-k $path) {
570 $$err_ref = "Sticky bit not set on $path when dir is group|world writable"
571 if ref($err_ref);
572 return 0;
573 }
574 }
575
576 return 1;
577}
578
579# Internal routine to check whether a directory is safe
580# for temp files. Safer than _is_safe since it checks for
581# the possibility of chown giveaway and if that is a possibility
582# checks each directory in the path to see if it is safe (with _is_safe)
583
584# If _PC_CHOWN_RESTRICTED is not set, does the full test of each
585# directory anyway.
586
587# Takes optional second arg as scalar ref to error reason
588
589sub _is_verysafe {
590
591 # Need POSIX - but only want to bother if really necessary due to overhead
592 require POSIX;
593
594 my $path = shift;
595 print "_is_verysafe testing $path\n" if $DEBUG;
596 return 1 if $^O eq 'VMS'; # owner delete control at file level
597
598 my $err_ref = shift;
599
600 # Should Get the value of _PC_CHOWN_RESTRICTED if it is defined
601 # and If it is not there do the extensive test
602 local($@);
603 my $chown_restricted;
604 $chown_restricted = &POSIX::_PC_CHOWN_RESTRICTED()
605 if eval { &POSIX::_PC_CHOWN_RESTRICTED(); 1};
606
607 # If chown_resticted is set to some value we should test it
608 if (defined $chown_restricted) {
609
610 # Return if the current directory is safe
611 return _is_safe($path,$err_ref) if POSIX::sysconf( $chown_restricted );
612
613 }
614
615 # To reach this point either, the _PC_CHOWN_RESTRICTED symbol
616 # was not available or the symbol was there but chown giveaway
617 # is allowed. Either way, we now have to test the entire tree for
618 # safety.
619
620 # Convert path to an absolute directory if required
621 unless (File::Spec->file_name_is_absolute($path)) {
622 $path = File::Spec->rel2abs($path);
623 }
624
625 # Split directory into components - assume no file
626 my ($volume, $directories, undef) = File::Spec->splitpath( $path, 1);
627
628 # Slightly less efficient than having a function in File::Spec
629 # to chop off the end of a directory or even a function that
630 # can handle ../ in a directory tree
631 # Sometimes splitdir() returns a blank at the end
632 # so we will probably check the bottom directory twice in some cases
633 my @dirs = File::Spec->splitdir($directories);
634
635 # Concatenate one less directory each time around
636 foreach my $pos (0.. $#dirs) {
637 # Get a directory name
638 my $dir = File::Spec->catpath($volume,
639 File::Spec->catdir(@dirs[0.. $#dirs - $pos]),
640 ''
641 );
642
643 print "TESTING DIR $dir\n" if $DEBUG;
644
645 # Check the directory
646 return 0 unless _is_safe($dir,$err_ref);
647
648 }
649
650 return 1;
651}
652
653# internal routine to determine whether unlink works on this
654# platform for files that are currently open.
655# Returns true if we can, false otherwise.
656
657# Currently WinNT, OS/2 and VMS can not unlink an opened file
658# On VMS this is because the O_EXCL flag is used to open the
659# temporary file. Currently I do not know enough about the issues
660# on VMS to decide whether O_EXCL is a requirement.
661
662sub _can_unlink_opened_file {
663
664 if (grep { $^O eq $_ } qw/MSWin32 os2 VMS dos MacOS haiku/) {
665 return 0;
666 } else {
667 return 1;
668 }
669
670}
671
672# internal routine to decide which security levels are allowed
673# see safe_level() for more information on this
674
675# Controls whether the supplied security level is allowed
676
677# $cando = _can_do_level( $level )
678
679sub _can_do_level {
680
681 # Get security level
682 my $level = shift;
683
684 # Always have to be able to do STANDARD
685 return 1 if $level == STANDARD;
686
687 # Currently, the systems that can do HIGH or MEDIUM are identical
688 if ( $^O eq 'MSWin32' || $^O eq 'os2' || $^O eq 'cygwin' || $^O eq 'dos' || $^O eq 'MacOS' || $^O eq 'mpeix') {
689 return 0;
690 } else {
691 return 1;
692 }
693
694}
695
696# This routine sets up a deferred unlinking of a specified
697# filename and filehandle. It is used in the following cases:
698# - Called by unlink0 if an opened file can not be unlinked
699# - Called by tempfile() if files are to be removed on shutdown
700# - Called by tempdir() if directories are to be removed on shutdown
701
702# Arguments:
703# _deferred_unlink( $fh, $fname, $isdir );
704#
705# - filehandle (so that it can be explicitly closed if open
706# - filename (the thing we want to remove)
707# - isdir (flag to indicate that we are being given a directory)
708# [and hence no filehandle]
709
710# Status is not referred to since all the magic is done with an END block
711
712{
713 # Will set up two lexical variables to contain all the files to be
714 # removed. One array for files, another for directories They will
715 # only exist in this block.
716
717 # This means we only have to set up a single END block to remove
718 # all files.
719
720 # in order to prevent child processes inadvertently deleting the parent
721 # temp files we use a hash to store the temp files and directories
722 # created by a particular process id.
723
724 # %files_to_unlink contains values that are references to an array of
725 # array references containing the filehandle and filename associated with
726 # the temp file.
7271500ns my (%files_to_unlink, %dirs_to_unlink);
728
729 # Set up an end block to use these arrays
730
# spent 69µs (30+38) within File::Temp::END which was called: # once (30µs+38µs) by main::RUNTIME at line 0 of /root/tor-browser-build/rbm/rbm
END {
731116µs local($., $@, $!, $^E, $?);
732112µs138µs cleanup(at_exit => 1);
# spent 38µs making 1 call to File::Temp::cleanup
733 }
734
735 # Cleanup function. Always triggered on END (with at_exit => 1) but
736 # can be invoked manually.
737
# spent 38µs (36+2) within File::Temp::cleanup which was called: # once (36µs+2µs) by File::Temp::END at line 732
sub cleanup {
73814µs my %h = @_;
73912µs my $at_exit = delete $h{at_exit};
74011µs $at_exit = 0 if not defined $at_exit;
741318µs12µs { my @k = sort keys %h; die "unrecognized parameters: @k" if @k }
# spent 2µs making 1 call to File::Temp::CORE:sort
742
743110µs if (!$KEEP_ALL) {
744 # Files
745 my @files = (exists $files_to_unlink{$$} ?
74612µs @{ $files_to_unlink{$$} } : () );
74711µs foreach my $file (@files) {
748 # close the filehandle without checking its state
749 # in order to make real sure that this is closed
750 # if its already closed then I don't care about the answer
751 # probably a better way to do this
752 close($file->[0]); # file handle is [0]
753
754 if (-f $file->[1]) { # file name is [1]
755 _force_writable( $file->[1] ); # for windows
756 unlink $file->[1] or warn "Error removing ".$file->[1];
757 }
758 }
759 # Dirs
760 my @dirs = (exists $dirs_to_unlink{$$} ?
76112µs @{ $dirs_to_unlink{$$} } : () );
7621400ns my ($cwd, $cwd_to_remove);
7631500ns foreach my $dir (@dirs) {
764 if (-d $dir) {
765 # Some versions of rmtree will abort if you attempt to remove
766 # the directory you are sitting in. For automatic cleanup
767 # at program exit, we avoid this by chdir()ing out of the way
768 # first. If not at program exit, it's best not to mess with the
769 # current directory, so just let it fail with a warning.
770 if ($at_exit) {
771 $cwd = Cwd::abs_path(File::Spec->curdir) if not defined $cwd;
772 my $abs = Cwd::abs_path($dir);
773 if ($abs eq $cwd) {
774 $cwd_to_remove = $dir;
775 next;
776 }
777 }
778 eval { rmtree($dir, $DEBUG, 0); };
779 warn $@ if ($@ && $^W);
780 }
781 }
782
78311µs if (defined $cwd_to_remove) {
784 # We do need to clean up the current directory, and everything
785 # else is done, so get out of there and remove it.
786 chdir $cwd_to_remove or die "cannot chdir to $cwd_to_remove: $!";
787 my $updir = File::Spec->updir;
788 chdir $updir or die "cannot chdir to $updir: $!";
789 eval { rmtree($cwd_to_remove, $DEBUG, 0); };
790 warn $@ if ($@ && $^W);
791 }
792
793 # clear the arrays
794 @{ $files_to_unlink{$$} } = ()
7951400ns if exists $files_to_unlink{$$};
796 @{ $dirs_to_unlink{$$} } = ()
7971700ns if exists $dirs_to_unlink{$$};
798 }
799 }
800
801 # This is the sub called to register a file for deferred unlinking
802 # This could simply store the input parameters and defer everything
803 # until the END block. For now we do a bit of checking at this
804 # point in order to make sure that (1) we have a file/dir to delete
805 # and (2) we have been called with the correct arguments.
806 sub _deferred_unlink {
807
808 croak 'Usage: _deferred_unlink($fh, $fname, $isdir)'
809 unless scalar(@_) == 3;
810
811 my ($fh, $fname, $isdir) = @_;
812
813 warn "Setting up deferred removal of $fname\n"
814 if $DEBUG;
815
816 # make sure we save the absolute path for later cleanup
817 # OK to untaint because we only ever use this internally
818 # as a file path, never interpolating into the shell
819 $fname = Cwd::abs_path($fname);
820 ($fname) = $fname =~ /^(.*)$/;
821
822 # If we have a directory, check that it is a directory
823 if ($isdir) {
824
825 if (-d $fname) {
826
827 # Directory exists so store it
828 # first on VMS turn []foo into [.foo] for rmtree
829 $fname = VMS::Filespec::vmspath($fname) if $^O eq 'VMS';
830 $dirs_to_unlink{$$} = []
831 unless exists $dirs_to_unlink{$$};
832 push (@{ $dirs_to_unlink{$$} }, $fname);
833
834 } else {
835 carp "Request to remove directory $fname could not be completed since it does not exist!\n" if $^W;
836 }
837
838 } else {
839
840 if (-f $fname) {
841
842 # file exists so store handle and name for later removal
843 $files_to_unlink{$$} = []
844 unless exists $files_to_unlink{$$};
845 push(@{ $files_to_unlink{$$} }, [$fh, $fname]);
846
847 } else {
848 carp "Request to remove file $fname could not be completed since it is not there!\n" if $^W;
849 }
850
851 }
852
853 }
854
855}
856
857# normalize argument keys to upper case and do consistent handling
858# of leading template vs TEMPLATE
8591100ns
# spent 38.0ms within File::Temp::_parse_args which was called 4587 times, avg 8µs/call: # 4583 times (37.9ms+0s) by File::Temp::tempfile at line 1009, avg 8µs/call # 2 times (29µs+0s) by File::Temp::newdir at line 914, avg 15µs/call # 2 times (7µs+0s) by File::Temp::tempdir at line 1137, avg 4µs/call
sub _parse_args {
86045877.30ms my $leading_template = (scalar(@_) % 2 == 1 ? shift(@_) : '' );
86145872.72ms my %args = @_;
86245877.11ms %args = map { uc($_), $args{$_} } keys %args;
863
864 # template (store it in an array so that it will
865 # disappear from the arg list of tempfile)
866 my @template = (
867 exists $args{TEMPLATE} ? $args{TEMPLATE} :
86845877.51ms $leading_template ? $leading_template : ()
869 );
87045871.63ms delete $args{TEMPLATE};
871
872458736.8ms return( \@template, \%args );
873}
874
875sub new {
876 my $proto = shift;
877 my $class = ref($proto) || $proto;
878
879 my ($maybe_template, $args) = _parse_args(@_);
880
881 # see if they are unlinking (defaulting to yes)
882 my $unlink = (exists $args->{UNLINK} ? $args->{UNLINK} : 1 );
883 delete $args->{UNLINK};
884
885 # Protect OPEN
886 delete $args->{OPEN};
887
888 # Open the file and retain file handle and file name
889 my ($fh, $path) = tempfile( @$maybe_template, %$args );
890
891 print "Tmp: $fh - $path\n" if $DEBUG;
892
893 # Store the filename in the scalar slot
894 ${*$fh} = $path;
895
896 # Cache the filename by pid so that the destructor can decide whether to remove it
897 $FILES_CREATED_BY_OBJECT{$$}{$path} = 1;
898
899 # Store unlink information in hash slot (plus other constructor info)
900 %{*$fh} = %$args;
901
902 # create the object
903 bless $fh, $class;
904
905 # final method-based configuration
906 $fh->unlink_on_destroy( $unlink );
907
908 return $fh;
909}
910
911
# spent 981µs (168+814) within File::Temp::newdir which was called 2 times, avg 491µs/call: # once (140µs+461µs) by RBM::build_run at line 1008 of /root/tor-browser-build/rbm/lib/RBM.pm # once (28µs+352µs) by RBM::DefaultConfig::rbm_tmp_dir at line 111 of /root/tor-browser-build/rbm/lib/RBM/DefaultConfig.pm
sub newdir {
91221µs my $self = shift;
913
91427µs229µs my ($maybe_template, $args) = _parse_args(@_);
# spent 29µs making 2 calls to File::Temp::_parse_args, avg 15µs/call
915
916 # handle CLEANUP without passing CLEANUP to tempdir
91722µs my $cleanup = (exists $args->{CLEANUP} ? $args->{CLEANUP} : 1 );
9182900ns delete $args->{CLEANUP};
919
92028µs2750µs my $tempdir = tempdir( @$maybe_template, %$args);
# spent 750µs making 2 calls to File::Temp::tempdir, avg 375µs/call
921
922 # get a safe absolute path for cleanup, just like
923 # happens in _deferred_unlink
924236µs228µs my $real_dir = Cwd::abs_path( $tempdir );
# spent 28µs making 2 calls to Cwd::abs_path, avg 14µs/call
9252122µs27µs ($real_dir) = $real_dir =~ /^(.*)$/;
# spent 7µs making 2 calls to File::Temp::CORE:match, avg 3µs/call
926
927224µs return bless { DIRNAME => $tempdir,
928 REALNAME => $real_dir,
929 CLEANUP => $cleanup,
930 LAUNCHPID => $$,
931 }, "File::Temp::Dir";
932}
933
934sub filename {
935 my $self = shift;
936 return ${*$self};
937}
938
939sub STRINGIFY {
940 my $self = shift;
941 return $self->filename;
942}
943
944# For reference, can't use '0+'=>\&Scalar::Util::refaddr directly because
945# refaddr() demands one parameter only, whereas overload.pm calls with three
946# even for unary operations like '0+'.
947
# spent 361µs (258+103) within File::Temp::NUMIFY which was called 25 times, avg 14µs/call: # 25 times (258µs+103µs) by RBM::DefaultConfig::rbm_tmp_dir at line 108 of /root/tor-browser-build/rbm/lib/RBM/DefaultConfig.pm, avg 14µs/call
sub NUMIFY {
94825373µs25103µs return refaddr($_[0]);
# spent 103µs making 25 calls to Scalar::Util::refaddr, avg 4µs/call
949}
950
951sub unlink_on_destroy {
952 my $self = shift;
953 if (@_) {
954 ${*$self}{UNLINK} = shift;
955 }
956 return ${*$self}{UNLINK};
957}
958
959sub DESTROY {
960 local($., $@, $!, $^E, $?);
961 my $self = shift;
962
963 # Make sure we always remove the file from the global hash
964 # on destruction. This prevents the hash from growing uncontrollably
965 # and post-destruction there is no reason to know about the file.
966 my $file = $self->filename;
967 my $was_created_by_proc;
968 if (exists $FILES_CREATED_BY_OBJECT{$$}{$file}) {
969 $was_created_by_proc = 1;
970 delete $FILES_CREATED_BY_OBJECT{$$}{$file};
971 }
972
973 if (${*$self}{UNLINK} && !$KEEP_ALL) {
974 print "# ---------> Unlinking $self\n" if $DEBUG;
975
976 # only delete if this process created it
977 return unless $was_created_by_proc;
978
979 # The unlink1 may fail if the file has been closed
980 # by the caller. This leaves us with the decision
981 # of whether to refuse to remove the file or simply
982 # do an unlink without test. Seems to be silly
983 # to do this when we are trying to be careful
984 # about security
985 _force_writable( $file ); # for windows
986 unlink1( $self, $file )
987 or unlink($file);
988 }
989}
990
991
# spent 1.64s (252ms+1.39) within File::Temp::tempfile which was called 4583 times, avg 358µs/call: # 4568 times (251ms+1.37s) by IO::CaptureOutput::_proxy::new at line 168 of IO/CaptureOutput.pm, avg 355µs/call # 15 times (903µs+14.4ms) by RBM::run_script at line 465 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 1.02ms/call
sub tempfile {
99245832.57ms if ( @_ && $_[0] eq 'File::Temp' ) {
993 croak "'tempfile' can't be called as a method";
994 }
995 # Can not check for argument count since we can have any
996 # number of args
997
998 # Default options
999458335.8ms my %options = (
1000 "DIR" => undef, # Directory prefix
1001 "SUFFIX" => '', # Template suffix
1002 "UNLINK" => 0, # Do not unlink file on exit
1003 "OPEN" => 1, # Open file
1004 "TMPDIR" => 0, # Place tempfile in tempdir if template specified
1005 "EXLOCK" => 1, # Open file with O_EXLOCK
1006 );
1007
1008 # Check to see whether we have an odd or even number of arguments
1009458313.6ms458337.9ms my ($maybe_template, $args) = _parse_args(@_);
# spent 37.9ms making 4583 calls to File::Temp::_parse_args, avg 8µs/call
101045833.22ms my $template = @$maybe_template ? $maybe_template->[0] : undef;
1011
1012 # Read the options and merge with defaults
1013458315.3ms %options = (%options, %$args);
1014
1015 # First decision is whether or not to open the file
101645833.69ms if (! $options{"OPEN"}) {
1017
1018 warn "tempfile(): temporary filename requested but not opened.\nPossibly unsafe, consider using tempfile() with OPEN set to true\n"
1019 if $^W;
1020
1021 }
1022
102345831.93ms if ($options{"DIR"} and $^O eq 'VMS') {
1024
1025 # on VMS turn []foo into [.foo] for concatenation
1026 $options{"DIR"} = VMS::Filespec::vmspath($options{"DIR"});
1027 }
1028
1029 # Construct the template
1030
1031 # Have a choice of trying to work around the mkstemp/mktemp/tmpnam etc
1032 # functions or simply constructing a template and using _gettemp()
1033 # explicitly. Go for the latter
1034
1035 # First generate a template if not defined and prefix the directory
1036 # If no template must prefix the temp directory
103745835.04ms if (defined $template) {
1038 # End up with current directory if neither DIR not TMPDIR are set
1039 if ($options{"DIR"}) {
1040
1041 $template = File::Spec->catfile($options{"DIR"}, $template);
1042
1043 } elsif ($options{TMPDIR}) {
1044
1045 $template = File::Spec->catfile(File::Spec->tmpdir, $template );
1046
1047 }
1048
1049 } else {
1050
105145833.13ms60792µs if ($options{"DIR"}) {
# spent 650µs making 15 calls to File::Spec::Unix::catfile, avg 43µs/call # spent 102µs making 15 calls to File::Spec::Unix::catdir, avg 7µs/call # spent 40µs making 30 calls to File::Spec::Unix::canonpath, avg 1µs/call
1052
1053 $template = File::Spec->catfile($options{"DIR"}, TEMPXXX);
1054
1055 } else {
1056
10574568182ms22840227ms $template = File::Spec->catfile(File::Spec->tmpdir, TEMPXXX);
# spent 103ms making 4568 calls to File::Spec::Unix::catfile, avg 23µs/call # spent 85.9ms making 4568 calls to File::Spec::Unix::tmpdir, avg 19µs/call # spent 28.9ms making 4568 calls to File::Spec::Unix::catdir, avg 6µs/call # spent 9.36ms making 9136 calls to File::Spec::Unix::canonpath, avg 1µs/call
1058
1059 }
1060
1061 }
1062
1063 # Now add a suffix
106445832.65ms $template .= $options{"SUFFIX"};
1065
1066 # Determine whether we should tell _gettemp to unlink the file
1067 # On unix this is irrelevant and can be worked out after the file is
1068 # opened (simply by unlinking the open filehandle). On Windows or VMS
1069 # we have to indicate temporary-ness when we open the file. In general
1070 # we only want a true temporary file if we are returning just the
1071 # filehandle - if the user wants the filename they probably do not
1072 # want the file to disappear as soon as they close it (which may be
1073 # important if they want a child process to use the file)
1074 # For this reason, tie unlink_on_close to the return context regardless
1075 # of OS.
107645833.28ms my $unlink_on_close = ( wantarray ? 0 : 1);
1077
1078 # Create the file
107945831.35ms my ($fh, $path, $errstr);
1080 croak "Error in tempfile() using template $template: $errstr"
1081 unless (($fh, $path) = _gettemp($template,
1082 "open" => $options{'OPEN'},
1083 "mkdir"=> 0 ,
1084 "unlink_on_close" => $unlink_on_close,
1085 "suffixlen" => length($options{'SUFFIX'}),
1086 "ErrStr" => \$errstr,
1087 "use_exlock" => $options{EXLOCK},
1088458320.7ms45831.16s ) );
# spent 1.16s making 4583 calls to File::Temp::_gettemp, avg 253µs/call
1089
1090 # Set up an exit handler that can do whatever is right for the
1091 # system. This removes files at exit when requested explicitly or when
1092 # system is asked to unlink_on_close but is unable to do so because
1093 # of OS limitations.
1094 # The latter should be achieved by using a tied filehandle.
1095 # Do not check return status since this is all done with END blocks.
109645832.37ms _deferred_unlink($fh, $path, 0) if $options{"UNLINK"};
1097
1098 # Return
1099458323.6ms if (wantarray()) {
1100
1101 if ($options{'OPEN'}) {
1102 return ($fh, $path);
1103 } else {
1104 return (undef, $path);
1105 }
1106
1107 } else {
1108
1109 # Unlink the file. It is up to unlink0 to decide what to do with
1110 # this (whether to unlink now or to defer until later)
1111 unlink0($fh, $path) or croak "Error unlinking file $path using unlink0";
1112
1113 # Return just the filehandle.
1114 return $fh;
1115 }
1116
1117}
1118
1119# '
1120
1121
# spent 750µs (77+672) within File::Temp::tempdir which was called 2 times, avg 375µs/call: # 2 times (77µs+672µs) by File::Temp::newdir at line 920, avg 375µs/call
sub tempdir {
112222µs if ( @_ && $_[0] eq 'File::Temp' ) {
1123 croak "'tempdir' can't be called as a method";
1124 }
1125
1126 # Can not check for argument count since we can have any
1127 # number of args
1128
1129 # Default options
113027µs my %options = (
1131 "CLEANUP" => 0, # Remove directory on exit
1132 "DIR" => '', # Root directory
1133 "TMPDIR" => 0, # Use tempdir with template
1134 );
1135
1136 # Check to see whether we have an odd or even number of arguments
113724µs27µs my ($maybe_template, $args) = _parse_args(@_);
# spent 7µs making 2 calls to File::Temp::_parse_args, avg 4µs/call
113823µs my $template = @$maybe_template ? $maybe_template->[0] : undef;
1139
1140 # Read the options and merge with defaults
114126µs %options = (%options, %$args);
1142
1143 # Modify or generate the template
1144
1145 # Deal with the DIR and TMPDIR options
114622µs if (defined $template) {
1147
1148 # Need to strip directory path if using DIR or TMPDIR
114923µs if ($options{'TMPDIR'} || $options{'DIR'}) {
1150
1151 # Strip parent directory from the filename
1152 #
1153 # There is no filename at the end
115411µs $template = VMS::Filespec::vmspath($template) if $^O eq 'VMS';
115516µs16µs my ($volume, $directories, undef) = File::Spec->splitpath( $template, 1);
# spent 6µs making 1 call to File::Spec::Unix::splitpath
1156
1157 # Last directory is then our template
115812µs12µs $template = (File::Spec->splitdir($directories))[-1];
# spent 2µs making 1 call to File::Spec::Unix::splitdir
1159
1160 # Prepend the supplied directory or temp dir
1161122µs216µs if ($options{"DIR"}) {
# spent 15µs making 1 call to File::Spec::Unix::catdir # spent 2µs making 1 call to File::Spec::Unix::canonpath
1162
1163 $template = File::Spec->catdir($options{"DIR"}, $template);
1164
1165 } elsif ($options{TMPDIR}) {
1166
1167 # Prepend tmpdir
1168 $template = File::Spec->catdir(File::Spec->tmpdir, $template);
1169
1170 }
1171
1172 }
1173
1174 } else {
1175
1176 if ($options{"DIR"}) {
1177
1178 $template = File::Spec->catdir($options{"DIR"}, TEMPXXX);
1179
1180 } else {
1181
1182 $template = File::Spec->catdir(File::Spec->tmpdir, TEMPXXX);
1183
1184 }
1185
1186 }
1187
1188 # Create the directory
11892900ns my $tempdir;
11902600ns my $suffixlen = 0;
119122µs if ($^O eq 'VMS') { # dir names can end in delimiters
1192 $template =~ m/([\.\]:>]+)$/;
1193 $suffixlen = length($1);
1194 }
119522µs if ( ($^O eq 'MacOS') && (substr($template, -1) eq ':') ) {
1196 # dir name has a trailing ':'
1197 ++$suffixlen;
1198 }
1199
12002500ns my $errstr;
1201210µs2642µs croak "Error in tempdir() using $template: $errstr"
# spent 642µs making 2 calls to File::Temp::_gettemp, avg 321µs/call
1202 unless ((undef, $tempdir) = _gettemp($template,
1203 "open" => 0,
1204 "mkdir"=> 1 ,
1205 "suffixlen" => $suffixlen,
1206 "ErrStr" => \$errstr,
1207 ) );
1208
1209 # Install exit handler; must be dynamic to get lexical
12102800ns if ( $options{'CLEANUP'} && -d $tempdir) {
1211 _deferred_unlink(undef, $tempdir, 1);
1212 }
1213
1214 # Return the dir name
121528µs return $tempdir;
1216
1217}
1218
1219sub mkstemp {
1220
1221 croak "Usage: mkstemp(template)"
1222 if scalar(@_) != 1;
1223
1224 my $template = shift;
1225
1226 my ($fh, $path, $errstr);
1227 croak "Error in mkstemp using $template: $errstr"
1228 unless (($fh, $path) = _gettemp($template,
1229 "open" => 1,
1230 "mkdir"=> 0 ,
1231 "suffixlen" => 0,
1232 "ErrStr" => \$errstr,
1233 ) );
1234
1235 if (wantarray()) {
1236 return ($fh, $path);
1237 } else {
1238 return $fh;
1239 }
1240
1241}
1242
1243sub mkstemps {
1244
1245 croak "Usage: mkstemps(template, suffix)"
1246 if scalar(@_) != 2;
1247
1248 my $template = shift;
1249 my $suffix = shift;
1250
1251 $template .= $suffix;
1252
1253 my ($fh, $path, $errstr);
1254 croak "Error in mkstemps using $template: $errstr"
1255 unless (($fh, $path) = _gettemp($template,
1256 "open" => 1,
1257 "mkdir"=> 0 ,
1258 "suffixlen" => length($suffix),
1259 "ErrStr" => \$errstr,
1260 ) );
1261
1262 if (wantarray()) {
1263 return ($fh, $path);
1264 } else {
1265 return $fh;
1266 }
1267
1268}
1269
1270#' # for emacs
1271
1272sub mkdtemp {
1273
1274 croak "Usage: mkdtemp(template)"
1275 if scalar(@_) != 1;
1276
1277 my $template = shift;
1278 my $suffixlen = 0;
1279 if ($^O eq 'VMS') { # dir names can end in delimiters
1280 $template =~ m/([\.\]:>]+)$/;
1281 $suffixlen = length($1);
1282 }
1283 if ( ($^O eq 'MacOS') && (substr($template, -1) eq ':') ) {
1284 # dir name has a trailing ':'
1285 ++$suffixlen;
1286 }
1287 my ($junk, $tmpdir, $errstr);
1288 croak "Error creating temp directory from template $template\: $errstr"
1289 unless (($junk, $tmpdir) = _gettemp($template,
1290 "open" => 0,
1291 "mkdir"=> 1 ,
1292 "suffixlen" => $suffixlen,
1293 "ErrStr" => \$errstr,
1294 ) );
1295
1296 return $tmpdir;
1297
1298}
1299
1300sub mktemp {
1301
1302 croak "Usage: mktemp(template)"
1303 if scalar(@_) != 1;
1304
1305 my $template = shift;
1306
1307 my ($tmpname, $junk, $errstr);
1308 croak "Error getting name to temp file from template $template: $errstr"
1309 unless (($junk, $tmpname) = _gettemp($template,
1310 "open" => 0,
1311 "mkdir"=> 0 ,
1312 "suffixlen" => 0,
1313 "ErrStr" => \$errstr,
1314 ) );
1315
1316 return $tmpname;
1317}
1318
1319sub tmpnam {
1320
1321 # Retrieve the temporary directory name
1322 my $tmpdir = File::Spec->tmpdir;
1323
1324 croak "Error temporary directory is not writable"
1325 if $tmpdir eq '';
1326
1327 # Use a ten character template and append to tmpdir
1328 my $template = File::Spec->catfile($tmpdir, TEMPXXX);
1329
1330 if (wantarray() ) {
1331 return mkstemp($template);
1332 } else {
1333 return mktemp($template);
1334 }
1335
1336}
1337
1338sub tmpfile {
1339
1340 # Simply call tmpnam() in a list context
1341 my ($fh, $file) = tmpnam();
1342
1343 # Make sure file is removed when filehandle is closed
1344 # This will fail on NFS
1345 unlink0($fh, $file)
1346 or return undef;
1347
1348 return $fh;
1349
1350}
1351
1352sub tempnam {
1353
1354 croak 'Usage tempnam($dir, $prefix)' unless scalar(@_) == 2;
1355
1356 my ($dir, $prefix) = @_;
1357
1358 # Add a string to the prefix
1359 $prefix .= 'XXXXXXXX';
1360
1361 # Concatenate the directory to the file
1362 my $template = File::Spec->catfile($dir, $prefix);
1363
1364 return mktemp($template);
1365
1366}
1367
1368sub unlink0 {
1369
1370 croak 'Usage: unlink0(filehandle, filename)'
1371 unless scalar(@_) == 2;
1372
1373 # Read args
1374 my ($fh, $path) = @_;
1375
1376 cmpstat($fh, $path) or return 0;
1377
1378 # attempt remove the file (does not work on some platforms)
1379 if (_can_unlink_opened_file()) {
1380
1381 # return early (Without unlink) if we have been instructed to retain files.
1382 return 1 if $KEEP_ALL;
1383
1384 # XXX: do *not* call this on a directory; possible race
1385 # resulting in recursive removal
1386 croak "unlink0: $path has become a directory!" if -d $path;
1387 unlink($path) or return 0;
1388
1389 # Stat the filehandle
1390 my @fh = stat $fh;
1391
1392 print "Link count = $fh[3] \n" if $DEBUG;
1393
1394 # Make sure that the link count is zero
1395 # - Cygwin provides deferred unlinking, however,
1396 # on Win9x the link count remains 1
1397 # On NFS the link count may still be 1 but we can't know that
1398 # we are on NFS. Since we can't be sure, we'll defer it
1399
1400 return 1 if $fh[3] == 0 || $^O eq 'cygwin';
1401 }
1402 # fall-through if we can't unlink now
1403 _deferred_unlink($fh, $path, 0);
1404 return 1;
1405}
1406
1407sub cmpstat {
1408
1409 croak 'Usage: cmpstat(filehandle, filename)'
1410 unless scalar(@_) == 2;
1411
1412 # Read args
1413 my ($fh, $path) = @_;
1414
1415 warn "Comparing stat\n"
1416 if $DEBUG;
1417
1418 # Stat the filehandle - which may be closed if someone has manually
1419 # closed the file. Can not turn off warnings without using $^W
1420 # unless we upgrade to 5.006 minimum requirement
1421 my @fh;
1422 {
1423 local ($^W) = 0;
1424 @fh = stat $fh;
1425 }
1426 return unless @fh;
1427
1428 if ($fh[3] > 1 && $^W) {
1429 carp "unlink0: fstat found too many links; SB=@fh" if $^W;
1430 }
1431
1432 # Stat the path
1433 my @path = stat $path;
1434
1435 unless (@path) {
1436 carp "unlink0: $path is gone already" if $^W;
1437 return;
1438 }
1439
1440 # this is no longer a file, but may be a directory, or worse
1441 unless (-f $path) {
1442 confess "panic: $path is no longer a file: SB=@fh";
1443 }
1444
1445 # Do comparison of each member of the array
1446 # On WinNT dev and rdev seem to be different
1447 # depending on whether it is a file or a handle.
1448 # Cannot simply compare all members of the stat return
1449 # Select the ones we can use
1450 my @okstat = (0..$#fh); # Use all by default
1451 if ($^O eq 'MSWin32') {
1452 @okstat = (1,2,3,4,5,7,8,9,10);
1453 } elsif ($^O eq 'os2') {
1454 @okstat = (0, 2..$#fh);
1455 } elsif ($^O eq 'VMS') { # device and file ID are sufficient
1456 @okstat = (0, 1);
1457 } elsif ($^O eq 'dos') {
1458 @okstat = (0,2..7,11..$#fh);
1459 } elsif ($^O eq 'mpeix') {
1460 @okstat = (0..4,8..10);
1461 }
1462
1463 # Now compare each entry explicitly by number
1464 for (@okstat) {
1465 print "Comparing: $_ : $fh[$_] and $path[$_]\n" if $DEBUG;
1466 # Use eq rather than == since rdev, blksize, and blocks (6, 11,
1467 # and 12) will be '' on platforms that do not support them. This
1468 # is fine since we are only comparing integers.
1469 unless ($fh[$_] eq $path[$_]) {
1470 warn "Did not match $_ element of stat\n" if $DEBUG;
1471 return 0;
1472 }
1473 }
1474
1475 return 1;
1476}
1477
1478sub unlink1 {
1479 croak 'Usage: unlink1(filehandle, filename)'
1480 unless scalar(@_) == 2;
1481
1482 # Read args
1483 my ($fh, $path) = @_;
1484
1485 cmpstat($fh, $path) or return 0;
1486
1487 # Close the file
1488 close( $fh ) or return 0;
1489
1490 # Make sure the file is writable (for windows)
1491 _force_writable( $path );
1492
1493 # return early (without unlink) if we have been instructed to retain files.
1494 return 1 if $KEEP_ALL;
1495
1496 # remove the file
1497 return unlink($path);
1498}
1499
1500{
1501 # protect from using the variable itself
15021200ns my $LEVEL = STANDARD;
1503
# spent 16.7ms within File::Temp::safe_level which was called 9170 times, avg 2µs/call: # 9170 times (16.7ms+0s) by File::Temp::_gettemp at line 335, avg 2µs/call
sub safe_level {
150491702.92ms my $self = shift;
150591702.60ms if (@_) {
1506 my $level = shift;
1507 if (($level != STANDARD) && ($level != MEDIUM) && ($level != HIGH)) {
1508 carp "safe_level: Specified level ($level) not STANDARD, MEDIUM or HIGH - ignoring\n" if $^W;
1509 } else {
1510 # Don't allow this on perl 5.005 or earlier
1511 if ($] < 5.006 && $level != STANDARD) {
1512 # Cant do MEDIUM or HIGH checks
1513 croak "Currently requires perl 5.006 or newer to do the safe checks";
1514 }
1515 # Check that we are allowed to change level
1516 # Silently ignore if we can not.
1517 $LEVEL = $level if _can_do_level($level);
1518 }
1519 }
1520917046.1ms return $LEVEL;
1521 }
1522}
1523
1524{
15252600ns my $TopSystemUID = 10;
15261500ns $TopSystemUID = 197108 if $^O eq 'interix'; # "Administrator"
1527 sub top_system_uid {
1528 my $self = shift;
1529 if (@_) {
1530 my $newuid = shift;
1531 croak "top_system_uid: UIDs should be numeric"
1532 unless $newuid =~ /^\d+$/s;
1533 $TopSystemUID = $newuid;
1534 }
1535 return $TopSystemUID;
1536 }
1537}
1538
15391200nspackage File::Temp::Dir;
1540
1541234µs2144µs
# spent 79µs (14+65) within File::Temp::Dir::BEGIN@1541 which was called: # once (14µs+65µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 1541
use File::Path qw/ rmtree /;
# spent 79µs making 1 call to File::Temp::Dir::BEGIN@1541 # spent 65µs making 1 call to Exporter::import
1542237µs219µs
# spent 14µs (9+5) within File::Temp::Dir::BEGIN@1542 which was called: # once (9µs+5µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 1542
use strict;
# spent 14µs making 1 call to File::Temp::Dir::BEGIN@1542 # spent 5µs making 1 call to strict::import
154317µs144µs
# spent 54µs (10+44) within File::Temp::Dir::BEGIN@1543 which was called: # once (10µs+44µs) by IO::CaptureOutput::_proxy::BEGIN@138 at line 1545
use overload '""' => "STRINGIFY",
# spent 44µs making 1 call to overload::import
1544 '0+' => \&File::Temp::NUMIFY,
15451352µs154µs fallback => 1;
# spent 54µs making 1 call to File::Temp::Dir::BEGIN@1543
1546
1547# private class specifically to support tempdir objects
1548# created by File::Temp->newdir
1549
1550# ostensibly the same method interface as File::Temp but without
1551# inheriting all the IO::Seekable methods and other cruft
1552
1553# Read-only - returns the name of the temp directory
1554
1555
# spent 205µs within File::Temp::Dir::dirname which was called 27 times, avg 8µs/call: # 25 times (178µs+0s) by RBM::DefaultConfig::rbm_tmp_dir at line 108 of /root/tor-browser-build/rbm/lib/RBM/DefaultConfig.pm, avg 7µs/call # once (23µs+0s) by RBM::build_run at line 1014 of /root/tor-browser-build/rbm/lib/RBM.pm # once (3µs+0s) by RBM::DefaultConfig::rbm_tmp_dir at line 113 of /root/tor-browser-build/rbm/lib/RBM/DefaultConfig.pm
sub dirname {
15562739µs my $self = shift;
155727206µs return $self->{DIRNAME};
1558}
1559
1560sub STRINGIFY {
1561 my $self = shift;
1562 return $self->dirname;
1563}
1564
1565
# spent 7µs within File::Temp::Dir::unlink_on_destroy which was called: # once (7µs+0s) by File::Temp::Dir::DESTROY at line 1576
sub unlink_on_destroy {
15661900ns my $self = shift;
156711µs if (@_) {
1568 $self->{CLEANUP} = shift;
1569 }
1570120µs return $self->{CLEANUP};
1571}
1572
1573
# spent 105ms (133µs+104) within File::Temp::Dir::DESTROY which was called: # once (133µs+104ms) by RBM::build_run at line 1163 of /root/tor-browser-build/rbm/lib/RBM.pm
sub DESTROY {
157411µs my $self = shift;
1575128µs local($., $@, $!, $^E, $?);
1576143µs17µs if ($self->unlink_on_destroy &&
# spent 7µs making 1 call to File::Temp::Dir::unlink_on_destroy
1577 $$ == $self->{LAUNCHPID} && !$File::Temp::KEEP_ALL) {
1578163µs113µs if (-d $self->{REALNAME}) {
# spent 13µs making 1 call to File::Temp::Dir::CORE:ftdir
1579 # Some versions of rmtree will abort if you attempt to remove
1580 # the directory you are sitting in. We protect that and turn it
1581 # into a warning. We do this because this occurs during object
1582 # destruction and so can not be caught by the user.
158326µs1104ms eval { rmtree($self->{REALNAME}, $File::Temp::DEBUG, 0); };
# spent 104ms making 1 call to File::Path::rmtree
15841600ns warn $@ if ($@ && $^W);
1585 }
1586 }
1587}
1588
1589126µs1;
1590
1591__END__
 
# spent 32.9ms within File::Temp::CORE:chmod which was called 4585 times, avg 7µs/call: # 4583 times (32.9ms+0s) by File::Temp::_gettemp at line 382, avg 7µs/call # 2 times (17µs+0s) by File::Temp::_gettemp at line 404, avg 9µs/call
sub File::Temp::CORE:chmod; # opcode
# spent 6.17ms within File::Temp::CORE:ftdir which was called 4585 times, avg 1µs/call: # 4585 times (6.17ms+0s) by File::Temp::_gettemp at line 326, avg 1µs/call
sub File::Temp::CORE:ftdir; # opcode
# spent 29.1ms within File::Temp::CORE:ftis which was called 4585 times, avg 6µs/call: # 4585 times (29.1ms+0s) by File::Temp::_gettemp at line 322, avg 6µs/call
sub File::Temp::CORE:ftis; # opcode
# spent 7µs within File::Temp::CORE:match which was called 2 times, avg 3µs/call: # 2 times (7µs+0s) by File::Temp::newdir at line 925, avg 3µs/call
sub File::Temp::CORE:match; # opcode
# spent 232µs within File::Temp::CORE:mkdir which was called 2 times, avg 116µs/call: # 2 times (232µs+0s) by File::Temp::_gettemp at line 402, avg 116µs/call
sub File::Temp::CORE:mkdir; # opcode
# spent 10.1ms within File::Temp::CORE:regcomp which was called 4585 times, avg 2µs/call: # 4585 times (10.1ms+0s) by File::Temp::_replace_XX at line 496, avg 2µs/call
sub File::Temp::CORE:regcomp; # opcode
# spent 2µs within File::Temp::CORE:sort which was called: # once (2µs+0s) by File::Temp::cleanup at line 741
sub File::Temp::CORE:sort; # opcode
# spent 22.8ms within File::Temp::CORE:subst which was called 4585 times, avg 5µs/call: # 4585 times (22.8ms+0s) by File::Temp::_replace_XX at line 496, avg 5µs/call
sub File::Temp::CORE:subst; # opcode
# spent 54.4ms within File::Temp::CORE:substcont which was called 50426 times, avg 1µs/call: # 50426 times (54.4ms+0s) by File::Temp::_replace_XX at line 496, avg 1µs/call
sub File::Temp::CORE:substcont; # opcode
# spent 222ms within File::Temp::CORE:sysopen which was called 4583 times, avg 48µs/call: # 4583 times (222ms+0s) by File::Temp::_gettemp at line 377, avg 48µs/call
sub File::Temp::CORE:sysopen; # opcode
# spent 13µs within File::Temp::Dir::CORE:ftdir which was called: # once (13µs+0s) by File::Temp::Dir::DESTROY at line 1578
sub File::Temp::Dir::CORE:ftdir; # opcode
# spent 600ns within File::Temp::__ANON__ which was called: # once (600ns+0s) by File::Temp::BEGIN@11 at line 11
sub File::Temp::__ANON__; # xsub