Skip to content

Commit

Permalink
Update File-Temp to CPAN version 0.2311
Browse files Browse the repository at this point in the history
  [DELTA]

0.2311    2020-10-03 04:04:15Z
          - Fix new PERMS test so as to also pass on root (RT#133443)

0.2310    2020-09-26 17:37:56Z
          - add AppVeyor CI
          - Add PERMS options to create temp file with given file permissions
          - remove remaining uses of indirect object syntax (#34, Nicolas R)
  • Loading branch information
karenetheridge committed Oct 3, 2020
1 parent 6009d3e commit 0df722d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Porting/Maintainers.pl
Expand Up @@ -535,7 +535,7 @@ package Maintainers;
},

'File::Temp' => {
'DISTRIBUTION' => 'ETHER/File-Temp-0.2309.tar.gz',
'DISTRIBUTION' => 'ETHER/File-Temp-0.2311.tar.gz',
'FILES' => q[cpan/File-Temp],
'EXCLUDED' => [
qw( README.mkdn
Expand Down
105 changes: 70 additions & 35 deletions cpan/File-Temp/lib/File/Temp.pm
@@ -1,7 +1,7 @@
package File::Temp; # git description: v0.2308-7-g3bb4d88
package File::Temp; # git description: v0.2310-3-gc7148fe
# ABSTRACT: return name and handle of a temporary file safely

our $VERSION = '0.2309';
our $VERSION = '0.2311';

#pod =begin :__INTERNALS
#pod
Expand Down Expand Up @@ -307,6 +307,7 @@ my %FILES_CREATED_BY_OBJECT;
# use of the O_TEMPORARY flag to sysopen.
# Usually irrelevant on unix
# "use_exlock" => Indicates that O_EXLOCK should be used. Default is false.
# "file_permissions" => file permissions for sysopen(). Default is 0600.

# 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
Expand Down Expand Up @@ -339,12 +340,13 @@ sub _gettemp {

# Default options
my %options = (
"open" => 0,
"mkdir" => 0,
"suffixlen" => 0,
"unlink_on_close" => 0,
"use_exlock" => 0,
"ErrStr" => \$tempErrStr,
"open" => 0,
"mkdir" => 0,
"suffixlen" => 0,
"unlink_on_close" => 0,
"use_exlock" => 0,
"ErrStr" => \$tempErrStr,
"file_permissions" => undef,
);

# Read the template
Expand Down Expand Up @@ -480,6 +482,9 @@ sub _gettemp {
}
}

my $perms = $options{file_permissions};
my $has_perms = defined $perms;
$perms = 0600 unless $has_perms;

# Now try MAX_TRIES time to open the file
for (my $i = 0; $i < MAX_TRIES; $i++) {
Expand All @@ -502,19 +507,19 @@ sub _gettemp {
my $open_success = undef;
if ( $^O eq 'VMS' and $options{"unlink_on_close"} && !$KEEP_ALL) {
# make it auto delete on close by setting FAB$V_DLT bit
$fh = VMS::Stdio::vmssysopen($path, $OPENFLAGS, 0600, 'fop=dlt');
$fh = VMS::Stdio::vmssysopen($path, $OPENFLAGS, $perms, 'fop=dlt');
$open_success = $fh;
} else {
my $flags = ( ($options{"unlink_on_close"} && !$KEEP_ALL) ?
$OPENTEMPFLAGS :
$OPENFLAGS );
$flags |= $LOCKFLAG if (defined $LOCKFLAG && $options{use_exlock});
$open_success = sysopen($fh, $path, $flags, 0600);
$open_success = sysopen($fh, $path, $flags, $perms);
}
if ( $open_success ) {

# in case of odd umask force rw
chmod(0600, $path);
chmod($perms, $path) unless $has_perms;

# Opened successfully - return file handle and name
return ($fh, $path);
Expand Down Expand Up @@ -799,7 +804,7 @@ sub _is_verysafe {

sub _can_unlink_opened_file {

if (grep { $^O eq $_ } qw/MSWin32 os2 VMS dos MacOS haiku/) {
if (grep $^O eq $_, qw/MSWin32 os2 VMS dos MacOS haiku/) {
return 0;
} else {
return 1;
Expand Down Expand Up @@ -999,7 +1004,7 @@ sub _can_do_level {
sub _parse_args {
my $leading_template = (scalar(@_) % 2 == 1 ? shift(@_) : '' );
my %args = @_;
%args = map { uc($_), $args{$_} } keys %args;
%args = map +(uc($_) => $args{$_}), keys %args;

# template (store it in an array so that it will
# disappear from the arg list of tempfile)
Expand Down Expand Up @@ -1048,7 +1053,8 @@ sub _parse_args {
#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 (defaulting to true), DIR, EXLOCK, PERMS and SUFFIX.
#pod Additionally, the filename
#pod template is specified using the TEMPLATE option. The OPEN option
#pod is not supported (the file is always opened).
#pod
Expand Down Expand Up @@ -1359,6 +1365,11 @@ sub DESTROY {
#pod
#pod ($fh, $filename) = tempfile($template, EXLOCK => 1);
#pod
#pod By default, the temp file is created with 0600 file permissions.
#pod Use C<PERMS> to change this:
#pod
#pod ($fh, $filename) = tempfile($template, PERMS => 0666);
#pod
#pod Options can be combined as required.
#pod
#pod Will croak() if there is an error.
Expand All @@ -1371,6 +1382,8 @@ sub DESTROY {
#pod
#pod EXLOCK flag available since 0.19.
#pod
#pod PERMS flag available since 0.2310.
#pod
#pod =cut

sub tempfile {
Expand All @@ -1386,8 +1399,9 @@ sub tempfile {
"SUFFIX" => '', # Template suffix
"UNLINK" => 0, # Do not unlink file on exit
"OPEN" => 1, # Open file
"TMPDIR" => 0, # Place tempfile in tempdir if template specified
"EXLOCK" => 0, # Open file with O_EXLOCK
"TMPDIR" => 0, # Place tempfile in tempdir if template specified
"EXLOCK" => 0, # Open file with O_EXLOCK
"PERMS" => undef, # File permissions
);

# Check to see whether we have an odd or even number of arguments
Expand Down Expand Up @@ -1464,12 +1478,13 @@ sub tempfile {
my ($fh, $path, $errstr);
croak "Error in tempfile() using template $template: $errstr"
unless (($fh, $path) = _gettemp($template,
"open" => $options{'OPEN'},
"mkdir"=> 0 ,
"unlink_on_close" => $unlink_on_close,
"suffixlen" => length($options{'SUFFIX'}),
"ErrStr" => \$errstr,
"use_exlock" => $options{EXLOCK},
"open" => $options{OPEN},
"mkdir" => 0,
"unlink_on_close" => $unlink_on_close,
"suffixlen" => length($options{SUFFIX}),
"ErrStr" => \$errstr,
"use_exlock" => $options{EXLOCK},
"file_permissions" => $options{PERMS},
) );

# Set up an exit handler that can do whatever is right for the
Expand Down Expand Up @@ -2581,7 +2596,7 @@ sub unlink1 {
package ## hide from PAUSE
File::Temp::Dir;

our $VERSION = '0.2309';
our $VERSION = '0.2311';

use File::Path qw/ rmtree /;
use strict;
Expand Down Expand Up @@ -2648,7 +2663,7 @@ File::Temp - return name and handle of a temporary file safely
=head1 VERSION
version 0.2309
version 0.2311
=head1 SYNOPSIS
Expand Down Expand Up @@ -2819,7 +2834,8 @@ that the temporary file is removed by the object destructor
if UNLINK is set to true (the default).
Supported arguments are the same as for C<tempfile>: UNLINK
(defaulting to true), DIR, EXLOCK and SUFFIX. Additionally, the filename
(defaulting to true), DIR, EXLOCK, PERMS and SUFFIX.
Additionally, the filename
template is specified using the TEMPLATE option. The OPEN option
is not supported (the file is always opened).
Expand Down Expand Up @@ -3004,6 +3020,11 @@ versions, explicitly set C<< EXLOCK=>0 >>.
($fh, $filename) = tempfile($template, EXLOCK => 1);
By default, the temp file is created with 0600 file permissions.
Use C<PERMS> to change this:
($fh, $filename) = tempfile($template, PERMS => 0666);
Options can be combined as required.
Will croak() if there is an error.
Expand All @@ -3016,6 +3037,8 @@ TMPDIR flag available since 0.19.
EXLOCK flag available since 0.19.
PERMS flag available since 0.2310.
=item B<tempdir>
This is the recommended interface for creation of temporary
Expand Down Expand Up @@ -3606,49 +3629,53 @@ 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
=for stopwords Tim Jenness Karen Etheridge David Golden Slaven Rezic mohawk2 Roy Ivy III Peter Rabbitson Olivier Mengué John Acklam Gim Yee Nicolas R Brian Mowrey Dagfinn Ilmari Mannsåker Steinbrunner Ed Avis Guillem Jover James E. Keenan Kevin Ryde Ben Tilly
=over 4
=item *
David Golden <dagolden@cpan.org>
Tim Jenness <t.jenness@jach.hawaii.edu>
=item *
Karen Etheridge <ether@cpan.org>
=item *
Slaven Rezic <slaven@rezic.de>
David Golden <dagolden@cpan.org>
=item *
Peter Rabbitson <ribasushi@cpan.org>
Slaven Rezic <srezic@cpan.org>
=item *
Olivier Mengue <dolmen@cpan.org>
mohawk2 <mohawk2@users.noreply.github.com>
=item *
David Golden <xdg@xdg.me>
Roy Ivy III <rivy.dev@gmail.com>
=item *
Kevin Ryde <user42@zip.com.au>
Peter Rabbitson <ribasushi@cpan.org>
=item *
Olivier Mengué <dolmen@cpan.org>
=item *
Peter John Acklam <pjacklam@online.no>
=item *
Slaven Rezic <slaven.rezic@idealo.de>
Tim Gim Yee <tim.gim.yee@gmail.com>
=item *
James E. Keenan <jkeen@verizon.net>
Nicolas R <atoomic@cpan.org>
=item *
Expand All @@ -3672,13 +3699,21 @@ Guillem Jover <guillem@hadrons.org>
=item *
James E. Keenan <jkeen@verizon.net>
=item *
Kevin Ryde <user42@zip.com.au>
=item *
Ben Tilly <btilly@gmail.com>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Tim Jenness and the UK Particle Physics and Astronomy Research Council.
This software is copyright (c) 2020 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.
Expand Down
2 changes: 1 addition & 1 deletion cpan/File-Temp/t/cmp.t
Expand Up @@ -7,7 +7,7 @@ use strict;
BEGIN {use_ok( "File::Temp" ); }

{
my $fh = new File::Temp();
my $fh = File::Temp->new();
isa_ok ($fh, 'File::Temp');

ok( "$fh" ne "foo", "compare stringified object with string");
Expand Down
14 changes: 8 additions & 6 deletions cpan/File-Temp/t/fork.t
Expand Up @@ -12,10 +12,14 @@ BEGIN {
$Config::Config{useithreads} and
$Config::Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/
);
if ( $can_fork ) {
if ( $can_fork && !(($^O eq 'MSWin32') && $Devel::Cover::VERSION) ) {
print "1..8\n";
} else {
print "1..0 # Skip No fork available\n";
if ( ($^O eq 'MSWin32') && $Devel::Cover::VERSION ) {
print "1..0 # Skip Devel::Cover coverage testing is incompatible with fork under 'MSWin32'\n";
} else {
print "1..0 # Skip No fork available\n";
}
exit;
}
}
Expand All @@ -38,8 +42,7 @@ for my $i (1 .. $children) {
} else {
# in a child we can't keep the count properly so we do it manually
# make sure that child 1 dies first
srand();
my $time = (($i-1) * 5) +int(rand(5));
my $time = ($i-1) * 3;
print "# child $i sleeping for $time seconds\n";
sleep($time);
my $count = $i + 1;
Expand Down Expand Up @@ -72,8 +75,7 @@ for my $i (1 .. $children) {
# parent process
next;
} else {
srand();
my $time = (($i-1) * 5) +int(rand(5));
my $time = ($i-1) * 3;
print "# child $i sleeping for $time seconds\n";
sleep($time);
my $count = 5 + $i;
Expand Down
2 changes: 1 addition & 1 deletion cpan/File-Temp/t/lock.t
Expand Up @@ -43,7 +43,7 @@ if ($@) {
ok( !$status, "File $fh is locked" );

# Now get a tempfile with locking disabled
$fh = new File::Temp( EXLOCK => 0 );
$fh = File::Temp->new( EXLOCK => 0 );

eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
Expand Down

0 comments on commit 0df722d

Please sign in to comment.