summaryrefslogtreecommitdiff
path: root/systems/texlive/tlnet/tlpkg/tlperl/lib/File/Temp.pm
diff options
context:
space:
mode:
Diffstat (limited to 'systems/texlive/tlnet/tlpkg/tlperl/lib/File/Temp.pm')
-rw-r--r--systems/texlive/tlnet/tlpkg/tlperl/lib/File/Temp.pm1210
1 files changed, 1151 insertions, 59 deletions
diff --git a/systems/texlive/tlnet/tlpkg/tlperl/lib/File/Temp.pm b/systems/texlive/tlnet/tlpkg/tlperl/lib/File/Temp.pm
index 817c6d90c6..39e15d5c3c 100644
--- a/systems/texlive/tlnet/tlpkg/tlperl/lib/File/Temp.pm
+++ b/systems/texlive/tlnet/tlpkg/tlperl/lib/File/Temp.pm
@@ -1,7 +1,142 @@
-package File::Temp;
+package File::Temp; # git description: v0.2308-7-g3bb4d88
# ABSTRACT: return name and handle of a temporary file safely
-our $VERSION = '0.2304'; # VERSION
+our $VERSION = '0.2309';
+
+#pod =begin :__INTERNALS
+#pod
+#pod =head1 PORTABILITY
+#pod
+#pod This section is at the top in order to provide easier access to
+#pod porters. It is not expected to be rendered by a standard pod
+#pod formatting tool. Please skip straight to the SYNOPSIS section if you
+#pod are not trying to port this module to a new platform.
+#pod
+#pod This module is designed to be portable across operating systems and it
+#pod currently supports Unix, VMS, DOS, OS/2, Windows and Mac OS
+#pod (Classic). When porting to a new OS there are generally three main
+#pod issues that have to be solved:
+#pod
+#pod =over 4
+#pod
+#pod =item *
+#pod
+#pod Can the OS unlink an open file? If it can not then the
+#pod C<_can_unlink_opened_file> method should be modified.
+#pod
+#pod =item *
+#pod
+#pod Are the return values from C<stat> reliable? By default all the
+#pod return values from C<stat> are compared when unlinking a temporary
+#pod file using the filename and the handle. Operating systems other than
+#pod unix do not always have valid entries in all fields. If utility function
+#pod C<File::Temp::unlink0> fails then the C<stat> comparison should be
+#pod modified accordingly.
+#pod
+#pod =item *
+#pod
+#pod Security. Systems that can not support a test for the sticky bit
+#pod on a directory can not use the MEDIUM and HIGH security tests.
+#pod The C<_can_do_level> method should be modified accordingly.
+#pod
+#pod =back
+#pod
+#pod =end :__INTERNALS
+#pod
+#pod =head1 SYNOPSIS
+#pod
+#pod use File::Temp qw/ tempfile tempdir /;
+#pod
+#pod $fh = tempfile();
+#pod ($fh, $filename) = tempfile();
+#pod
+#pod ($fh, $filename) = tempfile( $template, DIR => $dir);
+#pod ($fh, $filename) = tempfile( $template, SUFFIX => '.dat');
+#pod ($fh, $filename) = tempfile( $template, TMPDIR => 1 );
+#pod
+#pod binmode( $fh, ":utf8" );
+#pod
+#pod $dir = tempdir( CLEANUP => 1 );
+#pod ($fh, $filename) = tempfile( DIR => $dir );
+#pod
+#pod Object interface:
+#pod
+#pod require File::Temp;
+#pod use File::Temp ();
+#pod use File::Temp qw/ :seekable /;
+#pod
+#pod $fh = File::Temp->new();
+#pod $fname = $fh->filename;
+#pod
+#pod $fh = File::Temp->new(TEMPLATE => $template);
+#pod $fname = $fh->filename;
+#pod
+#pod $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' );
+#pod print $tmp "Some data\n";
+#pod print "Filename is $tmp\n";
+#pod $tmp->seek( 0, SEEK_END );
+#pod
+#pod $dir = File::Temp->newdir(); # CLEANUP => 1 by default
+#pod
+#pod The following interfaces are provided for compatibility with
+#pod existing APIs. They should not be used in new code.
+#pod
+#pod MkTemp family:
+#pod
+#pod use File::Temp qw/ :mktemp /;
+#pod
+#pod ($fh, $file) = mkstemp( "tmpfileXXXXX" );
+#pod ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix);
+#pod
+#pod $tmpdir = mkdtemp( $template );
+#pod
+#pod $unopened_file = mktemp( $template );
+#pod
+#pod POSIX functions:
+#pod
+#pod use File::Temp qw/ :POSIX /;
+#pod
+#pod $file = tmpnam();
+#pod $fh = tmpfile();
+#pod
+#pod ($fh, $file) = tmpnam();
+#pod
+#pod Compatibility functions:
+#pod
+#pod $unopened_file = File::Temp::tempnam( $dir, $pfx );
+#pod
+#pod =head1 DESCRIPTION
+#pod
+#pod C<File::Temp> can be used to create and open temporary files in a safe
+#pod way. There is both a function interface and an object-oriented
+#pod interface. The File::Temp constructor or the tempfile() function can
+#pod be used to return the name and the open filehandle of a temporary
+#pod file. The tempdir() function can be used to create a temporary
+#pod directory.
+#pod
+#pod The security aspect of temporary file creation is emphasized such that
+#pod a filehandle and filename are returned together. This helps guarantee
+#pod that a race condition can not occur where the temporary file is
+#pod created by another process between checking for the existence of the
+#pod file and its opening. Additional security levels are provided to
+#pod check, for example, that the sticky bit is set on world writable
+#pod directories. See L<"safe_level"> for more information.
+#pod
+#pod For compatibility with popular C library functions, Perl implementations of
+#pod the mkstemp() family of functions are provided. These are, mkstemp(),
+#pod mkstemps(), mkdtemp() and mktemp().
+#pod
+#pod Additionally, implementations of the standard L<POSIX|POSIX>
+#pod tmpnam() and tmpfile() functions are provided if required.
+#pod
+#pod Implementations of mktemp(), tmpnam(), and tempnam() are provided,
+#pod but should be used with caution since they return only a filename
+#pod that was valid when function was called, so cannot guarantee
+#pod that the file will not exist by the time the caller opens the filename.
+#pod
+#pod Filehandles returned by these functions support the seekable methods.
+#pod
+#pod =cut
# Toolchain targets v5.8.1, but we'll try to support back to v5.6 anyway.
# It might be possible to make this v5.5, but many v5.6isms are creeping
@@ -33,11 +168,8 @@ use parent 0.221 qw/ IO::Handle IO::Seekable /;
use overload '""' => "STRINGIFY", '0+' => "NUMIFY",
fallback => 1;
-# use 'our' on v5.6.0
-use vars qw(@EXPORT_OK %EXPORT_TAGS $DEBUG $KEEP_ALL);
-
-$DEBUG = 0;
-$KEEP_ALL = 0;
+our $DEBUG = 0;
+our $KEEP_ALL = 0;
# We are exporting functions
@@ -45,7 +177,7 @@ use Exporter 5.57 'import'; # 5.57 lets us import 'import'
# Export list - to allow fine tuning of export table
-@EXPORT_OK = qw{
+our @EXPORT_OK = qw{
tempfile
tempdir
tmpnam
@@ -63,7 +195,7 @@ use Exporter 5.57 'import'; # 5.57 lets us import 'import'
# Groups of functions for export
-%EXPORT_TAGS = (
+our %EXPORT_TAGS = (
'POSIX' => [qw/ tmpnam tmpfile /],
'mktemp' => [qw/ mktemp mkstemp mkstemps mkdtemp/],
'seekable' => [qw/ SEEK_SET SEEK_CUR SEEK_END /],
@@ -174,7 +306,7 @@ my %FILES_CREATED_BY_OBJECT;
# the file as soon as it is closed. Usually indicates
# use of the O_TEMPORARY flag to sysopen.
# Usually irrelevant on unix
-# "use_exlock" => Indicates that O_EXLOCK should be used. Default is true.
+# "use_exlock" => Indicates that O_EXLOCK should be used. Default is false.
# Optionally a reference to a scalar can be passed into the function
# On error this will be used to store the reason for the error
@@ -211,7 +343,7 @@ sub _gettemp {
"mkdir" => 0,
"suffixlen" => 0,
"unlink_on_close" => 0,
- "use_exlock" => 1,
+ "use_exlock" => 0,
"ErrStr" => \$tempErrStr,
);
@@ -437,7 +569,7 @@ sub _gettemp {
# 1 X say and the randomness could come up with the same
# file MAX_TRIES in a row.
- # Store current attempt - in principal this implies that the
+ # Store current attempt - in principle this implies that the
# 3rd time around the open attempt that the first temp file
# name could be generated again. Probably should store each
# attempt and make sure that none are repeated
@@ -880,6 +1012,59 @@ sub _parse_args {
return( \@template, \%args );
}
+#pod =head1 OBJECT-ORIENTED INTERFACE
+#pod
+#pod This is the primary interface for interacting with
+#pod C<File::Temp>. Using the OO interface a temporary file can be created
+#pod when the object is constructed and the file can be removed when the
+#pod object is no longer required.
+#pod
+#pod Note that there is no method to obtain the filehandle from the
+#pod C<File::Temp> object. The object itself acts as a filehandle. The object
+#pod isa C<IO::Handle> and isa C<IO::Seekable> so all those methods are
+#pod available.
+#pod
+#pod Also, the object is configured such that it stringifies to the name of the
+#pod temporary file and so can be compared to a filename directly. It numifies
+#pod to the C<refaddr> the same as other handles and so can be compared to other
+#pod handles with C<==>.
+#pod
+#pod $fh eq $filename # as a string
+#pod $fh != \*STDOUT # as a number
+#pod
+#pod Available since 0.14.
+#pod
+#pod =over 4
+#pod
+#pod =item B<new>
+#pod
+#pod Create a temporary file object.
+#pod
+#pod my $tmp = File::Temp->new();
+#pod
+#pod by default the object is constructed as if C<tempfile>
+#pod was called without options, but with the additional behaviour
+#pod that the temporary file is removed by the object destructor
+#pod if UNLINK is set to true (the default).
+#pod
+#pod Supported arguments are the same as for C<tempfile>: UNLINK
+#pod (defaulting to true), DIR, EXLOCK and SUFFIX. Additionally, the filename
+#pod template is specified using the TEMPLATE option. The OPEN option
+#pod is not supported (the file is always opened).
+#pod
+#pod $tmp = File::Temp->new( TEMPLATE => 'tempXXXXX',
+#pod DIR => 'mydir',
+#pod SUFFIX => '.dat');
+#pod
+#pod Arguments are case insensitive.
+#pod
+#pod Can call croak() if an error occurs.
+#pod
+#pod Available since 0.14.
+#pod
+#pod TEMPLATE available since 0.23
+#pod
+#pod =cut
sub new {
my $proto = shift;
@@ -917,6 +1102,27 @@ sub new {
return $fh;
}
+#pod =item B<newdir>
+#pod
+#pod Create a temporary directory using an object oriented interface.
+#pod
+#pod $dir = File::Temp->newdir();
+#pod
+#pod By default the directory is deleted when the object goes out of scope.
+#pod
+#pod Supports the same options as the C<tempdir> function. Note that directories
+#pod created with this method default to CLEANUP => 1.
+#pod
+#pod $dir = File::Temp->newdir( $template, %options );
+#pod
+#pod A template may be specified either with a leading template or
+#pod with a TEMPLATE argument.
+#pod
+#pod Available since 0.19.
+#pod
+#pod TEMPLATE available since 0.23.
+#pod
+#pod =cut
sub newdir {
my $self = shift;
@@ -941,6 +1147,19 @@ sub newdir {
}, "File::Temp::Dir";
}
+#pod =item B<filename>
+#pod
+#pod Return the name of the temporary file associated with this object
+#pod (if the object was created using the "new" constructor).
+#pod
+#pod $filename = $tmp->filename;
+#pod
+#pod This method is called automatically when the object is used as
+#pod a string.
+#pod
+#pod Current API available since 0.14
+#pod
+#pod =cut
sub filename {
my $self = shift;
@@ -959,6 +1178,27 @@ sub NUMIFY {
return refaddr($_[0]);
}
+#pod =item B<dirname>
+#pod
+#pod Return the name of the temporary directory associated with this
+#pod object (if the object was created using the "newdir" constructor).
+#pod
+#pod $dirname = $tmpdir->dirname;
+#pod
+#pod This method is called automatically when the object is used in string context.
+#pod
+#pod =item B<unlink_on_destroy>
+#pod
+#pod Control whether the file is unlinked when the object goes out of scope.
+#pod The file is removed if this value is true and $KEEP_ALL is not.
+#pod
+#pod $fh->unlink_on_destroy( 1 );
+#pod
+#pod Default is for the file to be removed.
+#pod
+#pod Current API available since 0.15
+#pod
+#pod =cut
sub unlink_on_destroy {
my $self = shift;
@@ -968,6 +1208,29 @@ sub unlink_on_destroy {
return ${*$self}{UNLINK};
}
+#pod =item B<DESTROY>
+#pod
+#pod When the object goes out of scope, the destructor is called. This
+#pod destructor will attempt to unlink the file (using L<unlink1|"unlink1">)
+#pod if the constructor was called with UNLINK set to 1 (the default state
+#pod if UNLINK is not specified).
+#pod
+#pod No error is given if the unlink fails.
+#pod
+#pod If the object has been passed to a child process during a fork, the
+#pod file will be deleted when the object goes out of scope in the parent.
+#pod
+#pod For a temporary directory object the directory will be removed unless
+#pod the CLEANUP argument was used in the constructor (and set to false) or
+#pod C<unlink_on_destroy> was modified after creation. Note that if a temp
+#pod directory is your current directory, it cannot be removed - a warning
+#pod will be given in this case. C<chdir()> out of the directory before
+#pod letting the object go out of scope.
+#pod
+#pod If the global variable $KEEP_ALL is true, the file or directory
+#pod will not be removed.
+#pod
+#pod =cut
sub DESTROY {
local($., $@, $!, $^E, $?);
@@ -1001,6 +1264,114 @@ sub DESTROY {
}
}
+#pod =back
+#pod
+#pod =head1 FUNCTIONS
+#pod
+#pod This section describes the recommended interface for generating
+#pod temporary files and directories.
+#pod
+#pod =over 4
+#pod
+#pod =item B<tempfile>
+#pod
+#pod This is the basic function to generate temporary files.
+#pod The behaviour of the file can be changed using various options:
+#pod
+#pod $fh = tempfile();
+#pod ($fh, $filename) = tempfile();
+#pod
+#pod Create a temporary file in the directory specified for temporary
+#pod files, as specified by the tmpdir() function in L<File::Spec>.
+#pod
+#pod ($fh, $filename) = tempfile($template);
+#pod
+#pod Create a temporary file in the current directory using the supplied
+#pod template. Trailing `X' characters are replaced with random letters to
+#pod generate the filename. At least four `X' characters must be present
+#pod at the end of the template.
+#pod
+#pod ($fh, $filename) = tempfile($template, SUFFIX => $suffix)
+#pod
+#pod Same as previously, except that a suffix is added to the template
+#pod after the `X' translation. Useful for ensuring that a temporary
+#pod filename has a particular extension when needed by other applications.
+#pod But see the WARNING at the end.
+#pod
+#pod ($fh, $filename) = tempfile($template, DIR => $dir);
+#pod
+#pod Translates the template as before except that a directory name
+#pod is specified.
+#pod
+#pod ($fh, $filename) = tempfile($template, TMPDIR => 1);
+#pod
+#pod Equivalent to specifying a DIR of "File::Spec->tmpdir", writing the file
+#pod into the same temporary directory as would be used if no template was
+#pod specified at all.
+#pod
+#pod ($fh, $filename) = tempfile($template, UNLINK => 1);
+#pod
+#pod Return the filename and filehandle as before except that the file is
+#pod automatically removed when the program exits (dependent on
+#pod $KEEP_ALL). Default is for the file to be removed if a file handle is
+#pod requested and to be kept if the filename is requested. In a scalar
+#pod context (where no filename is returned) the file is always deleted
+#pod either (depending on the operating system) on exit or when it is
+#pod closed (unless $KEEP_ALL is true when the temp file is created).
+#pod
+#pod Use the object-oriented interface if fine-grained control of when
+#pod a file is removed is required.
+#pod
+#pod If the template is not specified, a template is always
+#pod automatically generated. This temporary file is placed in tmpdir()
+#pod (L<File::Spec>) unless a directory is specified explicitly with the
+#pod DIR option.
+#pod
+#pod $fh = tempfile( DIR => $dir );
+#pod
+#pod If called in scalar context, only the filehandle is returned and the
+#pod file will automatically be deleted when closed on operating systems
+#pod that support this (see the description of tmpfile() elsewhere in this
+#pod document). This is the preferred mode of operation, as if you only
+#pod have a filehandle, you can never create a race condition by fumbling
+#pod with the filename. On systems that can not unlink an open file or can
+#pod not mark a file as temporary when it is opened (for example, Windows
+#pod NT uses the C<O_TEMPORARY> flag) the file is marked for deletion when
+#pod the program ends (equivalent to setting UNLINK to 1). The C<UNLINK>
+#pod flag is ignored if present.
+#pod
+#pod (undef, $filename) = tempfile($template, OPEN => 0);
+#pod
+#pod This will return the filename based on the template but
+#pod will not open this file. Cannot be used in conjunction with
+#pod UNLINK set to true. Default is to always open the file
+#pod to protect from possible race conditions. A warning is issued
+#pod if warnings are turned on. Consider using the tmpnam()
+#pod and mktemp() functions described elsewhere in this document
+#pod if opening the file is not required.
+#pod
+#pod To open the temporary filehandle with O_EXLOCK (open with exclusive
+#pod file lock) use C<< EXLOCK=>1 >>. This is supported only by some
+#pod operating systems (most notably BSD derived systems). By default
+#pod EXLOCK will be false. Former C<File::Temp> versions set EXLOCK to
+#pod true, so to be sure to get an unlocked filehandle also with older
+#pod versions, explicitly set C<< EXLOCK=>0 >>.
+#pod
+#pod ($fh, $filename) = tempfile($template, EXLOCK => 1);
+#pod
+#pod Options can be combined as required.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Available since 0.05.
+#pod
+#pod UNLINK flag available since 0.10.
+#pod
+#pod TMPDIR flag available since 0.19.
+#pod
+#pod EXLOCK flag available since 0.19.
+#pod
+#pod =cut
sub tempfile {
if ( @_ && $_[0] eq 'File::Temp' ) {
@@ -1016,7 +1387,7 @@ sub tempfile {
"UNLINK" => 0, # Do not unlink file on exit
"OPEN" => 1, # Open file
"TMPDIR" => 0, # Place tempfile in tempdir if template specified
- "EXLOCK" => 1, # Open file with O_EXLOCK
+ "EXLOCK" => 0, # Open file with O_EXLOCK
);
# Check to see whether we have an odd or even number of arguments
@@ -1056,7 +1427,7 @@ sub tempfile {
} elsif ($options{TMPDIR}) {
- $template = File::Spec->catfile(File::Spec->tmpdir, $template );
+ $template = File::Spec->catfile(_wrap_file_spec_tmpdir(), $template );
}
@@ -1068,7 +1439,7 @@ sub tempfile {
} else {
- $template = File::Spec->catfile(File::Spec->tmpdir, TEMPXXX);
+ $template = File::Spec->catfile(_wrap_file_spec_tmpdir(), TEMPXXX);
}
@@ -1131,6 +1502,122 @@ sub tempfile {
}
+# On Windows under taint mode, File::Spec could suggest "C:\" as a tempdir
+# which might not be writable. If that is the case, we fallback to a
+# user directory. See https://rt.cpan.org/Ticket/Display.html?id=60340
+
+{
+ my ($alt_tmpdir, $checked);
+
+ sub _wrap_file_spec_tmpdir {
+ return File::Spec->tmpdir unless $^O eq "MSWin32" && ${^TAINT};
+
+ if ( $checked ) {
+ return $alt_tmpdir ? $alt_tmpdir : File::Spec->tmpdir;
+ }
+
+ # probe what File::Spec gives and find a fallback
+ my $xxpath = _replace_XX( "X" x 10, 0 );
+
+ # First, see if File::Spec->tmpdir is writable
+ my $tmpdir = File::Spec->tmpdir;
+ my $testpath = File::Spec->catdir( $tmpdir, $xxpath );
+ if (mkdir( $testpath, 0700) ) {
+ $checked = 1;
+ rmdir $testpath;
+ return $tmpdir;
+ }
+
+ # Next, see if CSIDL_LOCAL_APPDATA is writable
+ require Win32;
+ my $local_app = File::Spec->catdir(
+ Win32::GetFolderPath( Win32::CSIDL_LOCAL_APPDATA() ), 'Temp'
+ );
+ $testpath = File::Spec->catdir( $local_app, $xxpath );
+ if ( -e $local_app or mkdir( $local_app, 0700 ) ) {
+ if (mkdir( $testpath, 0700) ) {
+ $checked = 1;
+ rmdir $testpath;
+ return $alt_tmpdir = $local_app;
+ }
+ }
+
+ # Can't find something writable
+ croak << "HERE";
+Couldn't find a writable temp directory in taint mode. Tried:
+ $tmpdir
+ $local_app
+
+Try setting and untainting the TMPDIR environment variable.
+HERE
+
+ }
+}
+
+#pod =item B<tempdir>
+#pod
+#pod This is the recommended interface for creation of temporary
+#pod directories. By default the directory will not be removed on exit
+#pod (that is, it won't be temporary; this behaviour can not be changed
+#pod because of issues with backwards compatibility). To enable removal
+#pod either use the CLEANUP option which will trigger removal on program
+#pod exit, or consider using the "newdir" method in the object interface which
+#pod will allow the directory to be cleaned up when the object goes out of
+#pod scope.
+#pod
+#pod The behaviour of the function depends on the arguments:
+#pod
+#pod $tempdir = tempdir();
+#pod
+#pod Create a directory in tmpdir() (see L<File::Spec|File::Spec>).
+#pod
+#pod $tempdir = tempdir( $template );
+#pod
+#pod Create a directory from the supplied template. This template is
+#pod similar to that described for tempfile(). `X' characters at the end
+#pod of the template are replaced with random letters to construct the
+#pod directory name. At least four `X' characters must be in the template.
+#pod
+#pod $tempdir = tempdir ( DIR => $dir );
+#pod
+#pod Specifies the directory to use for the temporary directory.
+#pod The temporary directory name is derived from an internal template.
+#pod
+#pod $tempdir = tempdir ( $template, DIR => $dir );
+#pod
+#pod Prepend the supplied directory name to the template. The template
+#pod should not include parent directory specifications itself. Any parent
+#pod directory specifications are removed from the template before
+#pod prepending the supplied directory.
+#pod
+#pod $tempdir = tempdir ( $template, TMPDIR => 1 );
+#pod
+#pod Using the supplied template, create the temporary directory in
+#pod a standard location for temporary files. Equivalent to doing
+#pod
+#pod $tempdir = tempdir ( $template, DIR => File::Spec->tmpdir);
+#pod
+#pod but shorter. Parent directory specifications are stripped from the
+#pod template itself. The C<TMPDIR> option is ignored if C<DIR> is set
+#pod explicitly. Additionally, C<TMPDIR> is implied if neither a template
+#pod nor a directory are supplied.
+#pod
+#pod $tempdir = tempdir( $template, CLEANUP => 1);
+#pod
+#pod Create a temporary directory using the supplied template, but
+#pod attempt to remove it (and all files inside it) when the program
+#pod exits. Note that an attempt will be made to remove all files from
+#pod the directory even if they were not created by this module (otherwise
+#pod why ask to clean it up?). The directory removal is made with
+#pod the rmtree() function from the L<File::Path|File::Path> module.
+#pod Of course, if the template is not specified, the temporary directory
+#pod will be created in tmpdir() and will also be removed at program exit.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Current API available since 0.05.
+#pod
+#pod =cut
# '
@@ -1181,7 +1668,7 @@ sub tempdir {
} elsif ($options{TMPDIR}) {
# Prepend tmpdir
- $template = File::Spec->catdir(File::Spec->tmpdir, $template);
+ $template = File::Spec->catdir(_wrap_file_spec_tmpdir(), $template);
}
@@ -1195,7 +1682,7 @@ sub tempdir {
} else {
- $template = File::Spec->catdir(File::Spec->tmpdir, TEMPXXX);
+ $template = File::Spec->catdir(_wrap_file_spec_tmpdir(), TEMPXXX);
}
@@ -1232,6 +1719,33 @@ sub tempdir {
}
+#pod =back
+#pod
+#pod =head1 MKTEMP FUNCTIONS
+#pod
+#pod The following functions are Perl implementations of the
+#pod mktemp() family of temp file generation system calls.
+#pod
+#pod =over 4
+#pod
+#pod =item B<mkstemp>
+#pod
+#pod Given a template, returns a filehandle to the temporary file and the name
+#pod of the file.
+#pod
+#pod ($fh, $name) = mkstemp( $template );
+#pod
+#pod In scalar context, just the filehandle is returned.
+#pod
+#pod The template may be any filename with some number of X's appended
+#pod to it, for example F</tmp/temp.XXXX>. The trailing X's are replaced
+#pod with unique alphanumeric combinations.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Current API available since 0.05.
+#pod
+#pod =cut
@@ -1260,6 +1774,23 @@ sub mkstemp {
}
+#pod =item B<mkstemps>
+#pod
+#pod Similar to mkstemp(), except that an extra argument can be supplied
+#pod with a suffix to be appended to the template.
+#pod
+#pod ($fh, $name) = mkstemps( $template, $suffix );
+#pod
+#pod For example a template of C<testXXXXXX> and suffix of C<.dat>
+#pod would generate a file similar to F<testhGji_w.dat>.
+#pod
+#pod Returns just the filehandle alone when called in scalar context.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Current API available since 0.05.
+#pod
+#pod =cut
sub mkstemps {
@@ -1289,6 +1820,22 @@ sub mkstemps {
}
+#pod =item B<mkdtemp>
+#pod
+#pod Create a directory from a template. The template must end in
+#pod X's that are replaced by the routine.
+#pod
+#pod $tmpdir_name = mkdtemp($template);
+#pod
+#pod Returns the name of the temporary directory created.
+#pod
+#pod Directory must be removed by the caller.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Current API available since 0.05.
+#pod
+#pod =cut
#' # for emacs
@@ -1320,6 +1867,20 @@ sub mkdtemp {
}
+#pod =item B<mktemp>
+#pod
+#pod Returns a valid temporary filename but does not guarantee
+#pod that the file will not be opened by someone else.
+#pod
+#pod $unopened_file = mktemp($template);
+#pod
+#pod Template is the same as that required by mkstemp().
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Current API available since 0.05.
+#pod
+#pod =cut
sub mktemp {
@@ -1340,12 +1901,57 @@ sub mktemp {
return $tmpname;
}
+#pod =back
+#pod
+#pod =head1 POSIX FUNCTIONS
+#pod
+#pod This section describes the re-implementation of the tmpnam()
+#pod and tmpfile() functions described in L<POSIX>
+#pod using the mkstemp() from this module.
+#pod
+#pod Unlike the L<POSIX|POSIX> implementations, the directory used
+#pod for the temporary file is not specified in a system include
+#pod file (C<P_tmpdir>) but simply depends on the choice of tmpdir()
+#pod returned by L<File::Spec|File::Spec>. On some implementations this
+#pod location can be set using the C<TMPDIR> environment variable, which
+#pod may not be secure.
+#pod If this is a problem, simply use mkstemp() and specify a template.
+#pod
+#pod =over 4
+#pod
+#pod =item B<tmpnam>
+#pod
+#pod When called in scalar context, returns the full name (including path)
+#pod of a temporary file (uses mktemp()). The only check is that the file does
+#pod not already exist, but there is no guarantee that that condition will
+#pod continue to apply.
+#pod
+#pod $file = tmpnam();
+#pod
+#pod When called in list context, a filehandle to the open file and
+#pod a filename are returned. This is achieved by calling mkstemp()
+#pod after constructing a suitable template.
+#pod
+#pod ($fh, $file) = tmpnam();
+#pod
+#pod If possible, this form should be used to prevent possible
+#pod race conditions.
+#pod
+#pod See L<File::Spec/tmpdir> for information on the choice of temporary
+#pod directory for a particular operating system.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Current API available since 0.05.
+#pod
+#pod =cut
sub tmpnam {
# Retrieve the temporary directory name
- my $tmpdir = File::Spec->tmpdir;
+ my $tmpdir = _wrap_file_spec_tmpdir();
+ # XXX I don't know under what circumstances this occurs, -- xdg 2016-04-02
croak "Error temporary directory is not writable"
if $tmpdir eq '';
@@ -1360,6 +1966,26 @@ sub tmpnam {
}
+#pod =item B<tmpfile>
+#pod
+#pod Returns the filehandle of a temporary file.
+#pod
+#pod $fh = tmpfile();
+#pod
+#pod The file is removed when the filehandle is closed or when the program
+#pod exits. No access to the filename is provided.
+#pod
+#pod If the temporary file can not be created undef is returned.
+#pod Currently this command will probably not work when the temporary
+#pod directory is on an NFS file system.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Available since 0.05.
+#pod
+#pod Returning undef if unable to create file added in 0.12.
+#pod
+#pod =cut
sub tmpfile {
@@ -1375,6 +2001,38 @@ sub tmpfile {
}
+#pod =back
+#pod
+#pod =head1 ADDITIONAL FUNCTIONS
+#pod
+#pod These functions are provided for backwards compatibility
+#pod with common tempfile generation C library functions.
+#pod
+#pod They are not exported and must be addressed using the full package
+#pod name.
+#pod
+#pod =over 4
+#pod
+#pod =item B<tempnam>
+#pod
+#pod Return the name of a temporary file in the specified directory
+#pod using a prefix. The file is guaranteed not to exist at the time
+#pod the function was called, but such guarantees are good for one
+#pod clock tick only. Always use the proper form of C<sysopen>
+#pod with C<O_CREAT | O_EXCL> if you must open such a filename.
+#pod
+#pod $filename = File::Temp::tempnam( $dir, $prefix );
+#pod
+#pod Equivalent to running mktemp() with $dir/$prefixXXXXXXXX
+#pod (using unix file convention as an example)
+#pod
+#pod Because this function uses mktemp(), it can suffer from race conditions.
+#pod
+#pod Will croak() if there is an error.
+#pod
+#pod Current API available since 0.05.
+#pod
+#pod =cut
sub tempnam {
@@ -1392,6 +2050,65 @@ sub tempnam {
}
+#pod =back
+#pod
+#pod =head1 UTILITY FUNCTIONS
+#pod
+#pod Useful functions for dealing with the filehandle and filename.
+#pod
+#pod =over 4
+#pod
+#pod =item B<unlink0>
+#pod
+#pod Given an open filehandle and the associated filename, make a safe
+#pod unlink. This is achieved by first checking that the filename and
+#pod filehandle initially point to the same file and that the number of
+#pod links to the file is 1 (all fields returned by stat() are compared).
+#pod Then the filename is unlinked and the filehandle checked once again to
+#pod verify that the number of links on that file is now 0. This is the
+#pod closest you can come to making sure that the filename unlinked was the
+#pod same as the file whose descriptor you hold.
+#pod
+#pod unlink0($fh, $path)
+#pod or die "Error unlinking file $path safely";
+#pod
+#pod Returns false on error but croaks() if there is a security
+#pod anomaly. The filehandle is not closed since on some occasions this is
+#pod not required.
+#pod
+#pod On some platforms, for example Windows NT, it is not possible to
+#pod unlink an open file (the file must be closed first). On those
+#pod platforms, the actual unlinking is deferred until the program ends and
+#pod good status is returned. A check is still performed to make sure that
+#pod the filehandle and filename are pointing to the same thing (but not at
+#pod the time the end block is executed since the deferred removal may not
+#pod have access to the filehandle).
+#pod
+#pod Additionally, on Windows NT not all the fields returned by stat() can
+#pod be compared. For example, the C<dev> and C<rdev> fields seem to be
+#pod different. Also, it seems that the size of the file returned by stat()
+#pod does not always agree, with C<stat(FH)> being more accurate than
+#pod C<stat(filename)>, presumably because of caching issues even when
+#pod using autoflush (this is usually overcome by waiting a while after
+#pod writing to the tempfile before attempting to C<unlink0> it).
+#pod
+#pod Finally, on NFS file systems the link count of the file handle does
+#pod not always go to zero immediately after unlinking. Currently, this
+#pod command is expected to fail on NFS disks.
+#pod
+#pod This function is disabled if the global variable $KEEP_ALL is true
+#pod and an unlink on open file is supported. If the unlink is to be deferred
+#pod to the END block, the file is still registered for removal.
+#pod
+#pod This function should not be called if you are using the object oriented
+#pod interface since the it will interfere with the object destructor deleting
+#pod the file.
+#pod
+#pod Available Since 0.05.
+#pod
+#pod If can not unlink open file, defer removal until later available since 0.06.
+#pod
+#pod =cut
sub unlink0 {
@@ -1432,6 +2149,32 @@ sub unlink0 {
return 1;
}
+#pod =item B<cmpstat>
+#pod
+#pod Compare C<stat> of filehandle with C<stat> of provided filename. This
+#pod can be used to check that the filename and filehandle initially point
+#pod to the same file and that the number of links to the file is 1 (all
+#pod fields returned by stat() are compared).
+#pod
+#pod cmpstat($fh, $path)
+#pod or die "Error comparing handle with file";
+#pod
+#pod Returns false if the stat information differs or if the link count is
+#pod greater than 1. Calls croak if there is a security anomaly.
+#pod
+#pod On certain platforms, for example Windows, not all the fields returned by stat()
+#pod can be compared. For example, the C<dev> and C<rdev> fields seem to be
+#pod different in Windows. Also, it seems that the size of the file
+#pod returned by stat() does not always agree, with C<stat(FH)> being more
+#pod accurate than C<stat(filename)>, presumably because of caching issues
+#pod even when using autoflush (this is usually overcome by waiting a while
+#pod after writing to the tempfile before attempting to C<unlink0> it).
+#pod
+#pod Not exported by default.
+#pod
+#pod Current API available since 0.14.
+#pod
+#pod =cut
sub cmpstat {
@@ -1504,6 +2247,29 @@ sub cmpstat {
return 1;
}
+#pod =item B<unlink1>
+#pod
+#pod Similar to C<unlink0> except after file comparison using cmpstat, the
+#pod filehandle is closed prior to attempting to unlink the file. This
+#pod allows the file to be removed without using an END block, but does
+#pod mean that the post-unlink comparison of the filehandle state provided
+#pod by C<unlink0> is not available.
+#pod
+#pod unlink1($fh, $path)
+#pod or die "Error closing and unlinking file";
+#pod
+#pod Usually called from the object destructor when using the OO interface.
+#pod
+#pod Not exported by default.
+#pod
+#pod This function is disabled if the global variable $KEEP_ALL is true.
+#pod
+#pod Can call croak() if there is a security anomaly during the stat()
+#pod comparison.
+#pod
+#pod Current API available since 0.14.
+#pod
+#pod =cut
sub unlink1 {
croak 'Usage: unlink1(filehandle, filename)'
@@ -1527,6 +2293,107 @@ sub unlink1 {
return unlink($path);
}
+#pod =item B<cleanup>
+#pod
+#pod Calling this function will cause any temp files or temp directories
+#pod that are registered for removal to be removed. This happens automatically
+#pod when the process exits but can be triggered manually if the caller is sure
+#pod that none of the temp files are required. This method can be registered as
+#pod an Apache callback.
+#pod
+#pod Note that if a temp directory is your current directory, it cannot be
+#pod removed. C<chdir()> out of the directory first before calling
+#pod C<cleanup()>. (For the cleanup at program exit when the CLEANUP flag
+#pod is set, this happens automatically.)
+#pod
+#pod On OSes where temp files are automatically removed when the temp file
+#pod is closed, calling this function will have no effect other than to remove
+#pod temporary directories (which may include temporary files).
+#pod
+#pod File::Temp::cleanup();
+#pod
+#pod Not exported by default.
+#pod
+#pod Current API available since 0.15.
+#pod
+#pod =back
+#pod
+#pod =head1 PACKAGE VARIABLES
+#pod
+#pod These functions control the global state of the package.
+#pod
+#pod =over 4
+#pod
+#pod =item B<safe_level>
+#pod
+#pod Controls the lengths to which the module will go to check the safety of the
+#pod temporary file or directory before proceeding.
+#pod Options are:
+#pod
+#pod =over 8
+#pod
+#pod =item STANDARD
+#pod
+#pod Do the basic security measures to ensure the directory exists and is
+#pod writable, that temporary files are opened only if they do not already
+#pod exist, and that possible race conditions are avoided. Finally the
+#pod L<unlink0|"unlink0"> function is used to remove files safely.
+#pod
+#pod =item MEDIUM
+#pod
+#pod In addition to the STANDARD security, the output directory is checked
+#pod to make sure that it is owned either by root or the user running the
+#pod program. If the directory is writable by group or by other, it is then
+#pod checked to make sure that the sticky bit is set.
+#pod
+#pod Will not work on platforms that do not support the C<-k> test
+#pod for sticky bit.
+#pod
+#pod =item HIGH
+#pod
+#pod In addition to the MEDIUM security checks, also check for the
+#pod possibility of ``chown() giveaway'' using the L<POSIX|POSIX>
+#pod sysconf() function. If this is a possibility, each directory in the
+#pod path is checked in turn for safeness, recursively walking back to the
+#pod root directory.
+#pod
+#pod For platforms that do not support the L<POSIX|POSIX>
+#pod C<_PC_CHOWN_RESTRICTED> symbol (for example, Windows NT) it is
+#pod assumed that ``chown() giveaway'' is possible and the recursive test
+#pod is performed.
+#pod
+#pod =back
+#pod
+#pod The level can be changed as follows:
+#pod
+#pod File::Temp->safe_level( File::Temp::HIGH );
+#pod
+#pod The level constants are not exported by the module.
+#pod
+#pod Currently, you must be running at least perl v5.6.0 in order to
+#pod run with MEDIUM or HIGH security. This is simply because the
+#pod safety tests use functions from L<Fcntl|Fcntl> that are not
+#pod available in older versions of perl. The problem is that the version
+#pod number for Fcntl is the same in perl 5.6.0 and in 5.005_03 even though
+#pod they are different versions.
+#pod
+#pod On systems that do not support the HIGH or MEDIUM safety levels
+#pod (for example Win NT or OS/2) any attempt to change the level will
+#pod be ignored. The decision to ignore rather than raise an exception
+#pod allows portable programs to be written with high security in mind
+#pod for the systems that can support this without those programs failing
+#pod on systems where the extra tests are irrelevant.
+#pod
+#pod If you really need to see whether the change has been accepted
+#pod simply examine the return value of C<safe_level>.
+#pod
+#pod $newlevel = File::Temp->safe_level( File::Temp::HIGH );
+#pod die "Could not change to high security"
+#pod if $newlevel != File::Temp::HIGH;
+#pod
+#pod Available since 0.05.
+#pod
+#pod =cut
{
# protect from using the variable itself
@@ -1552,6 +2419,28 @@ sub unlink1 {
}
}
+#pod =item TopSystemUID
+#pod
+#pod This is the highest UID on the current system that refers to a root
+#pod UID. This is used to make sure that the temporary directory is
+#pod owned by a system UID (C<root>, C<bin>, C<sys> etc) rather than
+#pod simply by root.
+#pod
+#pod This is required since on many unix systems C</tmp> is not owned
+#pod by root.
+#pod
+#pod Default is to assume that any UID less than or equal to 10 is a root
+#pod UID.
+#pod
+#pod File::Temp->top_system_uid(10);
+#pod my $topid = File::Temp->top_system_uid;
+#pod
+#pod This value can be adjusted to reduce security checking if required.
+#pod The value is only relevant when C<safe_level> is set to MEDIUM or higher.
+#pod
+#pod Available since 0.05.
+#pod
+#pod =cut
{
my $TopSystemUID = 10;
@@ -1568,8 +2457,131 @@ sub unlink1 {
}
}
-
-package File::Temp::Dir;
+#pod =item B<$KEEP_ALL>
+#pod
+#pod Controls whether temporary files and directories should be retained
+#pod regardless of any instructions in the program to remove them
+#pod automatically. This is useful for debugging but should not be used in
+#pod production code.
+#pod
+#pod $File::Temp::KEEP_ALL = 1;
+#pod
+#pod Default is for files to be removed as requested by the caller.
+#pod
+#pod In some cases, files will only be retained if this variable is true
+#pod when the file is created. This means that you can not create a temporary
+#pod file, set this variable and expect the temp file to still be around
+#pod when the program exits.
+#pod
+#pod =item B<$DEBUG>
+#pod
+#pod Controls whether debugging messages should be enabled.
+#pod
+#pod $File::Temp::DEBUG = 1;
+#pod
+#pod Default is for debugging mode to be disabled.
+#pod
+#pod Available since 0.15.
+#pod
+#pod =back
+#pod
+#pod =head1 WARNING
+#pod
+#pod For maximum security, endeavour always to avoid ever looking at,
+#pod touching, or even imputing the existence of the filename. You do not
+#pod know that that filename is connected to the same file as the handle
+#pod you have, and attempts to check this can only trigger more race
+#pod conditions. It's far more secure to use the filehandle alone and
+#pod dispense with the filename altogether.
+#pod
+#pod If you need to pass the handle to something that expects a filename
+#pod then on a unix system you can use C<"/dev/fd/" . fileno($fh)> for
+#pod arbitrary programs. Perl code that uses the 2-argument version of
+#pod C<< open >> can be passed C<< "+<=&" . fileno($fh) >>. Otherwise you
+#pod will need to pass the filename. You will have to clear the
+#pod close-on-exec bit on that file descriptor before passing it to another
+#pod process.
+#pod
+#pod use Fcntl qw/F_SETFD F_GETFD/;
+#pod fcntl($tmpfh, F_SETFD, 0)
+#pod or die "Can't clear close-on-exec flag on temp fh: $!\n";
+#pod
+#pod =head2 Temporary files and NFS
+#pod
+#pod Some problems are associated with using temporary files that reside
+#pod on NFS file systems and it is recommended that a local filesystem
+#pod is used whenever possible. Some of the security tests will most probably
+#pod fail when the temp file is not local. Additionally, be aware that
+#pod the performance of I/O operations over NFS will not be as good as for
+#pod a local disk.
+#pod
+#pod =head2 Forking
+#pod
+#pod In some cases files created by File::Temp are removed from within an
+#pod END block. Since END blocks are triggered when a child process exits
+#pod (unless C<POSIX::_exit()> is used by the child) File::Temp takes care
+#pod to only remove those temp files created by a particular process ID. This
+#pod means that a child will not attempt to remove temp files created by the
+#pod parent process.
+#pod
+#pod If you are forking many processes in parallel that are all creating
+#pod temporary files, you may need to reset the random number seed using
+#pod srand(EXPR) in each child else all the children will attempt to walk
+#pod through the same set of random file names and may well cause
+#pod themselves to give up if they exceed the number of retry attempts.
+#pod
+#pod =head2 Directory removal
+#pod
+#pod Note that if you have chdir'ed into the temporary directory and it is
+#pod subsequently cleaned up (either in the END block or as part of object
+#pod destruction), then you will get a warning from File::Path::rmtree().
+#pod
+#pod =head2 Taint mode
+#pod
+#pod If you need to run code under taint mode, updating to the latest
+#pod L<File::Spec> is highly recommended. On Windows, if the directory
+#pod given by L<File::Spec::tmpdir> isn't writable, File::Temp will attempt
+#pod to fallback to the user's local application data directory or croak
+#pod with an error.
+#pod
+#pod =head2 BINMODE
+#pod
+#pod The file returned by File::Temp will have been opened in binary mode
+#pod if such a mode is available. If that is not correct, use the C<binmode()>
+#pod function to change the mode of the filehandle.
+#pod
+#pod Note that you can modify the encoding of a file opened by File::Temp
+#pod also by using C<binmode()>.
+#pod
+#pod =head1 HISTORY
+#pod
+#pod Originally began life in May 1999 as an XS interface to the system
+#pod mkstemp() function. In March 2000, the OpenBSD mkstemp() code was
+#pod translated to Perl for total control of the code's
+#pod security checking, to ensure the presence of the function regardless of
+#pod operating system and to help with portability. The module was shipped
+#pod as a standard part of perl from v5.6.1.
+#pod
+#pod Thanks to Tom Christiansen for suggesting that this module
+#pod should be written and providing ideas for code improvements and
+#pod security enhancements.
+#pod
+#pod =head1 SEE ALSO
+#pod
+#pod L<POSIX/tmpnam>, L<POSIX/tmpfile>, L<File::Spec>, L<File::Path>
+#pod
+#pod See L<IO::File> and L<File::MkTemp>, L<Apache::TempFile> for
+#pod different implementations of temporary file handling.
+#pod
+#pod See L<File::Tempdir> for an alternative object-oriented wrapper for
+#pod the C<tempdir> function.
+#pod
+#pod =cut
+
+package ## hide from PAUSE
+ File::Temp::Dir;
+
+our $VERSION = '0.2309';
use File::Path qw/ rmtree /;
use strict;
@@ -1621,11 +2633,14 @@ sub DESTROY {
1;
+
+# vim: ts=2 sts=2 sw=2 et:
+
__END__
=pod
-=encoding utf-8
+=encoding UTF-8
=head1 NAME
@@ -1633,7 +2648,7 @@ File::Temp - return name and handle of a temporary file safely
=head1 VERSION
-version 0.2304
+version 0.2309
=head1 SYNOPSIS
@@ -1668,6 +2683,8 @@ Object interface:
print "Filename is $tmp\n";
$tmp->seek( 0, SEEK_END );
+ $dir = File::Temp->newdir(); # CLEANUP => 1 by default
+
The following interfaces are provided for compatibility with
existing APIs. They should not be used in new code.
@@ -1726,7 +2743,7 @@ that the file will not exist by the time the caller opens the filename.
Filehandles returned by these functions support the seekable methods.
-=begin __INTERNALS
+=begin :__INTERNALS
=head1 PORTABILITY
@@ -1739,6 +2756,7 @@ This module is designed to be portable across operating systems and it
currently supports Unix, VMS, DOS, OS/2, Windows and Mac OS
(Classic). When porting to a new OS there are generally three main
issues that have to be solved:
+
=over 4
=item *
@@ -1763,7 +2781,7 @@ The C<_can_do_level> method should be modified accordingly.
=back
-=end __INTERNALS
+=end :__INTERNALS
=head1 OBJECT-ORIENTED INTERFACE
@@ -1785,6 +2803,8 @@ handles with C<==>.
$fh eq $filename # as a string
$fh != \*STDOUT # as a number
+Available since 0.14.
+
=over 4
=item B<new>
@@ -1811,6 +2831,10 @@ Arguments are case insensitive.
Can call croak() if an error occurs.
+Available since 0.14.
+
+TEMPLATE available since 0.23
+
=item B<newdir>
Create a temporary directory using an object oriented interface.
@@ -1827,6 +2851,10 @@ created with this method default to CLEANUP => 1.
A template may be specified either with a leading template or
with a TEMPLATE argument.
+Available since 0.19.
+
+TEMPLATE available since 0.23.
+
=item B<filename>
Return the name of the temporary file associated with this object
@@ -1837,6 +2865,8 @@ Return the name of the temporary file associated with this object
This method is called automatically when the object is used as
a string.
+Current API available since 0.14
+
=item B<dirname>
Return the name of the temporary directory associated with this
@@ -1855,6 +2885,8 @@ The file is removed if this value is true and $KEEP_ALL is not.
Default is for the file to be removed.
+Current API available since 0.15
+
=item B<DESTROY>
When the object goes out of scope, the destructor is called. This
@@ -1963,20 +2995,27 @@ if warnings are turned on. Consider using the tmpnam()
and mktemp() functions described elsewhere in this document
if opening the file is not required.
-If the operating system supports it (for example BSD derived systems), the
-filehandle will be opened with O_EXLOCK (open with exclusive file lock).
-This can sometimes cause problems if the intention is to pass the filename
-to another system that expects to take an exclusive lock itself (such as
-DBD::SQLite) whilst ensuring that the tempfile is not reused. In this
-situation the "EXLOCK" option can be passed to tempfile. By default EXLOCK
-will be true (this retains compatibility with earlier releases).
+To open the temporary filehandle with O_EXLOCK (open with exclusive
+file lock) use C<< EXLOCK=>1 >>. This is supported only by some
+operating systems (most notably BSD derived systems). By default
+EXLOCK will be false. Former C<File::Temp> versions set EXLOCK to
+true, so to be sure to get an unlocked filehandle also with older
+versions, explicitly set C<< EXLOCK=>0 >>.
- ($fh, $filename) = tempfile($template, EXLOCK => 0);
+ ($fh, $filename) = tempfile($template, EXLOCK => 1);
Options can be combined as required.
Will croak() if there is an error.
+Available since 0.05.
+
+UNLINK flag available since 0.10.
+
+TMPDIR flag available since 0.19.
+
+EXLOCK flag available since 0.19.
+
=item B<tempdir>
This is the recommended interface for creation of temporary
@@ -2038,6 +3077,8 @@ will be created in tmpdir() and will also be removed at program exit.
Will croak() if there is an error.
+Current API available since 0.05.
+
=back
=head1 MKTEMP FUNCTIONS
@@ -2062,6 +3103,8 @@ with unique alphanumeric combinations.
Will croak() if there is an error.
+Current API available since 0.05.
+
=item B<mkstemps>
Similar to mkstemp(), except that an extra argument can be supplied
@@ -2076,6 +3119,8 @@ Returns just the filehandle alone when called in scalar context.
Will croak() if there is an error.
+Current API available since 0.05.
+
=item B<mkdtemp>
Create a directory from a template. The template must end in
@@ -2089,6 +3134,8 @@ Directory must be removed by the caller.
Will croak() if there is an error.
+Current API available since 0.05.
+
=item B<mktemp>
Returns a valid temporary filename but does not guarantee
@@ -2100,6 +3147,8 @@ Template is the same as that required by mkstemp().
Will croak() if there is an error.
+Current API available since 0.05.
+
=back
=head1 POSIX FUNCTIONS
@@ -2141,6 +3190,8 @@ directory for a particular operating system.
Will croak() if there is an error.
+Current API available since 0.05.
+
=item B<tmpfile>
Returns the filehandle of a temporary file.
@@ -2156,6 +3207,10 @@ directory is on an NFS file system.
Will croak() if there is an error.
+Available since 0.05.
+
+Returning undef if unable to create file added in 0.12.
+
=back
=head1 ADDITIONAL FUNCTIONS
@@ -2185,6 +3240,8 @@ Because this function uses mktemp(), it can suffer from race conditions.
Will croak() if there is an error.
+Current API available since 0.05.
+
=back
=head1 UTILITY FUNCTIONS
@@ -2239,6 +3296,10 @@ This function should not be called if you are using the object oriented
interface since the it will interfere with the object destructor deleting
the file.
+Available Since 0.05.
+
+If can not unlink open file, defer removal until later available since 0.06.
+
=item B<cmpstat>
Compare C<stat> of filehandle with C<stat> of provided filename. This
@@ -2262,6 +3323,8 @@ after writing to the tempfile before attempting to C<unlink0> it).
Not exported by default.
+Current API available since 0.14.
+
=item B<unlink1>
Similar to C<unlink0> except after file comparison using cmpstat, the
@@ -2282,6 +3345,8 @@ This function is disabled if the global variable $KEEP_ALL is true.
Can call croak() if there is a security anomaly during the stat()
comparison.
+Current API available since 0.14.
+
=item B<cleanup>
Calling this function will cause any temp files or temp directories
@@ -2303,6 +3368,8 @@ temporary directories (which may include temporary files).
Not exported by default.
+Current API available since 0.15.
+
=back
=head1 PACKAGE VARIABLES
@@ -2378,6 +3445,8 @@ simply examine the return value of C<safe_level>.
die "Could not change to high security"
if $newlevel != File::Temp::HIGH;
+Available since 0.05.
+
=item TopSystemUID
This is the highest UID on the current system that refers to a root
@@ -2397,6 +3466,8 @@ UID.
This value can be adjusted to reduce security checking if required.
The value is only relevant when C<safe_level> is set to MEDIUM or higher.
+Available since 0.05.
+
=item B<$KEEP_ALL>
Controls whether temporary files and directories should be retained
@@ -2421,6 +3492,8 @@ Controls whether debugging messages should be enabled.
Default is for debugging mode to be disabled.
+Available since 0.15.
+
=back
=head1 WARNING
@@ -2477,7 +3550,10 @@ destruction), then you will get a warning from File::Path::rmtree().
=head2 Taint mode
If you need to run code under taint mode, updating to the latest
-L<File::Spec> is highly recommended.
+L<File::Spec> is highly recommended. On Windows, if the directory
+given by L<File::Spec::tmpdir> isn't writable, File::Temp will attempt
+to fallback to the user's local application data directory or croak
+with an error.
=head2 BINMODE
@@ -2513,26 +3589,16 @@ the C<tempdir> function.
=for Pod::Coverage STRINGIFY NUMIFY top_system_uid
-# vim: ts=2 sts=2 sw=2 et:
-
-=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
-
=head1 SUPPORT
-=head2 Bugs / Feature Requests
-
-Please report any bugs or feature requests through the issue tracker
-at L<http://rt.cpan.org/Public/Dist/Display.html?Name=File-Temp>.
-You will be notified automatically of any progress on your issue.
-
-=head2 Source Code
+Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=File-Temp>
+(or L<bug-File-Temp@rt.cpan.org|mailto:bug-File-Temp@rt.cpan.org>).
-This is open source software. The code repository is available for
-public review and contribution under the terms of the license.
+There is also a mailing list available for users of this distribution, at
+L<http://lists.perl.org/list/cpan-workers.html>.
-L<https://github.com/Perl-Toolchain-Gang/File-Temp>
-
- git clone https://github.com/Perl-Toolchain-Gang/File-Temp.git
+There is also an irc channel available for users of this distribution, at
+L<C<#toolchain> on C<irc.perl.org>|irc://irc.perl.org/#toolchain>.
=head1 AUTHOR
@@ -2540,31 +3606,33 @@ Tim Jenness <tjenness@cpan.org>
=head1 CONTRIBUTORS
+=for stopwords David Golden Karen Etheridge Slaven Rezic Peter Rabbitson Olivier Mengue Kevin Ryde John Acklam James E. Keenan Brian Mowrey Dagfinn Ilmari Mannsåker Steinbrunner Ed Avis Guillem Jover Ben Tilly
+
=over 4
=item *
-Ben Tilly <btilly@gmail.com>
+David Golden <dagolden@cpan.org>
=item *
-David Golden <dagolden@cpan.org>
+Karen Etheridge <ether@cpan.org>
=item *
-David Steinbrunner <dsteinbrunner@pobox.com>
+Slaven Rezic <slaven@rezic.de>
=item *
-Ed Avis <eda@linux01.wcl.local>
+Peter Rabbitson <ribasushi@cpan.org>
=item *
-James E. Keenan <jkeen@verizon.net>
+Olivier Mengue <dolmen@cpan.org>
=item *
-Karen Etheridge <ether@cpan.org>
+David Golden <xdg@xdg.me>
=item *
@@ -2572,21 +3640,45 @@ Kevin Ryde <user42@zip.com.au>
=item *
-Olivier Mengue <dolmen@cpan.org>
+Peter John Acklam <pjacklam@online.no>
=item *
-Peter John Acklam <pjacklam@online.no>
+Slaven Rezic <slaven.rezic@idealo.de>
=item *
-Peter Rabbitson <ribasushi@cpan.org>
+James E. Keenan <jkeen@verizon.net>
+
+=item *
+
+Brian Mowrey <brian@drlabs.org>
+
+=item *
+
+Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
+
+=item *
+
+David Steinbrunner <dsteinbrunner@pobox.com>
+
+=item *
+
+Ed Avis <eda@linux01.wcl.local>
+
+=item *
+
+Guillem Jover <guillem@hadrons.org>
+
+=item *
+
+Ben Tilly <btilly@gmail.com>
=back
=head1 COPYRIGHT AND LICENSE
-This software is copyright (c) 2013 by Tim Jenness and the UK Particle Physics and Astronomy Research Council.
+This software is copyright (c) 2019 by Tim Jenness and the UK Particle Physics and Astronomy Research Council.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.