Front page | perl.perl5.porters |
Postings from November 2013
[perl #120593] File::Spec::Unix->tmpdir: Always return an absolute path
Thread Next
From:
Brian Fraser
Date:
November 20, 2013 04:15
Subject:
[perl #120593] File::Spec::Unix->tmpdir: Always return an absolute path
Message ID:
rt-4.0.18-10570-1384920924-1378.120593-75-0@perl.org
# New Ticket Created by Brian Fraser
# Please include the string: [perl #120593]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=120593 >
This is a bug report for perl from fraserbn@gmail.com,
generated with the help of perlbug 1.39 running under perl 5.16.2.
-----------------------------------------------------------------
[Please describe your issue here]
This is generally a non-issue, however, if /tmp doesn't exist
and $ENV{TMPDIR} isn't set, ->tmpdir() used to return ".", which
broke the following pattern:
use File::Temp qw(tempdir);
use File::Spec;
my $tmpdir = tempdir(CLEANUP => 1);
chdir $tmpdir;
my $file = File::Spec->catfile($tmpdir, "foo");
open my $fh, ">", $file or die $!;
Because $tmpdir would be something like 'bfhskjf94589', and after
the chdir, the open() would've tried to open $tmpdir/$tmpdir/foo.
(note that the patch doesn't up the version of Cwd and friends)
---
dist/Cwd/lib/File/Spec/Unix.pm | 3 +++
dist/Cwd/t/tmpdir.t | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/dist/Cwd/lib/File/Spec/Unix.pm b/dist/Cwd/lib/File/Spec/Unix.pm
index 868b6a7..7030994 100644
--- a/dist/Cwd/lib/File/Spec/Unix.pm
+++ b/dist/Cwd/lib/File/Spec/Unix.pm
@@ -193,6 +193,9 @@ sub _tmpdir {
}
$tmpdir = $self->curdir unless defined $tmpdir;
$tmpdir = defined $tmpdir && $self->canonpath($tmpdir);
+ if ( $tmpdir eq '.' ) {
+ $tmpdir = defined $tmpdir && $self->rel2abs($tmpdir);
+ }
return $tmpdir;
}
diff --git a/dist/Cwd/t/tmpdir.t b/dist/Cwd/t/tmpdir.t
index 7c13da1..0f03dc5 100644
--- a/dist/Cwd/t/tmpdir.t
+++ b/dist/Cwd/t/tmpdir.t
@@ -1,5 +1,5 @@
use strict;
-use Test::More tests => 7;
+use Test::More tests => 8;
# Grab all of the plain routines from File::Spec
use File::Spec;
@@ -46,3 +46,8 @@ for ('File::Spec', "File::Spec::Win32") {
isn't $tmpdir2, $tmpdir1, "$_->tmpdir works with changing env";
}
}
+
+ok(
+ File::Spec->file_name_is_absolute(File::Spec->tmpdir()),
+ "tmpdir() always returns an absolute path"
+);
--
[Please do not change anything below this line]
--------------------------------------------------------------------
Flags:
category=core
severity=low
---
Site configuration information for perl 5.16.2:
Configured by hugmeir at Tue Nov 20 17:20:00 ART 2012.
Summary of my perl5 (revision 5 version 16 subversion 2) configuration:
Platform:
osname=linux, osvers=3.5.0-18-generic,
archname=x86_64-linux-thread-multi
uname='linux naw 3.5.0-18-generic #29-ubuntu smp fri oct 19 10:26:51
utc 2012 x86_64 x86_64 x86_64 gnulinux '
config_args='-de
-Dprefix=/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2 -DDEBUGGING
-Dusethreads -Doptimize=-g -O0 -ggdb3 -Uversiononly -Accflags=-Wall -Wextra
-Aeval:scriptdir=/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/bin'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -Wall -Wextra -DDEBUGGING
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-g -O0 -ggdb3',
cppflags='-D_REENTRANT -D_GNU_SOURCE -Wall -Wextra -DDEBUGGING
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.7.2', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib/x86_64-linux-gnu /lib/../lib
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib /usr/lib
libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.15'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -g -O0 -ggdb3 -L/usr/local/lib
-fstack-protector'
Locally applied patches:
---
@INC for perl 5.16.2:
/home/hugmeir/.perlbrew/libs/perl-5.16.2@all
/lib/perl5/x86_64-linux-thread-multi
/home/hugmeir/.perlbrew/libs/perl-5.16.2@all/lib/perl5
/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/lib/site_perl/5.16.2/x86_64-linux-thread-multi
/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/lib/site_perl/5.16.2
/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2/x86_64-linux-thread-multi
/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/lib/5.16.2
.
---
Environment for perl 5.16.2:
HOME=/home/hugmeir
LANG=en_US.UTF-8
LANGUAGE=en_US
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/hugmeir/.perlbrew/libs/perl-5.16.2@all
/bin:/home/hugmeir/perl5/perlbrew/bin:/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PERL5LIB=/home/hugmeir/.perlbrew/libs/perl-5.16.2@all/lib/perl5
PERLBREW_BASHRC_VERSION=0.66
PERLBREW_HOME=/home/hugmeir/.perlbrew
PERLBREW_LIB=all
PERLBREW_MANPATH=/home/hugmeir/.perlbrew/libs/perl-5.16.2@all
/man:/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/man
PERLBREW_PATH=/home/hugmeir/.perlbrew/libs/perl-5.16.2@all
/bin:/home/hugmeir/perl5/perlbrew/bin:/home/hugmeir/perl5/perlbrew/perls/perl-5.16.2/bin
PERLBREW_PERL=perl-5.16.2
PERLBREW_ROOT=/home/hugmeir/perl5/perlbrew
PERLBREW_VERSION=0.66
PERL_BADLANG (unset)
PERL_LOCAL_LIB_ROOT=/home/hugmeir/.perlbrew/libs/perl-5.16.2@all
PERL_MB_OPT=--install_base /home/hugmeir/.perlbrew/libs/perl-5.16.2@all
PERL_MM_OPT=INSTALL_BASE=/home/hugmeir/.perlbrew/libs/perl-5.16.2@all
SHELL=/bin/bash
Thread Next
-
[perl #120593] File::Spec::Unix->tmpdir: Always return an absolute path
by Brian Fraser