Subject: | tmpdir with -T on Windows |
I found a 'Temp Directory "Bug"' this weekend:
http://blogs.perl.org/users/mr_muskrat/2010/08/temp-directory-bug.html.
I was installing some modules and one of the tests in a dependency
module failed:
http://www.nntp.perl.org/group/perl.cpan.testers/2010/08/msg7663252.html.
I tracked it back to File::Temp's tempfile subroutine and reported a
bug: https://rt.cpan.org/Ticket/Display.html?id=60340. Had I kept going,
I would have found that File::Temp uses File::Spec.
C:\Users\mmusgrove\Documents>perl -MFile::Spec -e 'print File::Spec->tmpdir'
Can't find string terminator "'" anywhere before EOF at -e line 1.
When tmpdir is called normally, a sane temporary directory is returned:
C:\Users\mmusgrove\Documents>perl -MFile::Spec -e "print File::Spec->tmpdir"
C:\Users\MMUSGR~1\AppData\Local\Temp
When tmpdir is called with -T, a not so sane directory is returned
(namely \):
C:\Users\mmusgrove\Documents>perl -T -MFile::Spec -e "print
File::Spec->tmpdir"
\
Looking at the docs for File::Spec::Win32 and -T, it says that tmpdir
will simply throw out the environment variables if they are tainted.
This would be fine if it used sane temporary directories but only one of
the ones it looks for actually exists on most Windows systems (that
would be '\'; however, that directory will NOT be writable on recent
versions of Windows such as Vista and Windows 7. 'C:\TEMP\' may or may
not exist on Window 3.x or Windows 9x but more than likely will not
exist on Windows NT, 2k, XP, Vista or Windows 7. To further complicate
things, Windows doesn't seem to provide a temporary directory that is
writable by all users.
Yes, I could create C:\system\temp or C:\TEMP and make it writable by
me. Yes, I could make \ writable by me. Whether anyone agrees with me or
not, I don't feel like I should have to. I also feel very strongly that
neither should the new guy who wants to give this "perl thing" a try.
CPAN module installs should just work and File::Spec is used by more
than a few modules so this makes the most sense as the place to fix it.
I agree with Curtis Jewell's statement, "What it should do in -T mode,
IMO, is to check %TEMP% against a logical regex for Windows filenames
(there's none in Regex::Common except for file: URI's, or I'd recommend
that), capture if that regex works, and then check for that directory's
existence."