develooper Front page | perl.perl5.porters | Postings from March 2003

File::Spec::tmpdir cleanup need

Thread Next
From:
Jarkko Hietaniemi
Date:
March 12, 2003 07:31
Subject:
File::Spec::tmpdir cleanup need
Message ID:
20030312153114.GM1273@kosh.hut.fi
I just run into a bug in File::Spec.  Well, two.  Well, many.

(1) In Cygwin if $ENV{TMPDIR} was unset, the File::Temp tests
    ended up trying to create files at the root directory, which failed.
    Workaround: create File::Spec::Cygwin::tmpdir which also attempts
    to use c:/temp (a fair bet in Cygwin...) (change #18955).

    Why I think this is a workaround, not a fix?  Read on.

(2) I looked at the tmpdir()s of File::Spec and they all had this
    exact line or its moral equivalent:

	$tmpdir = '' unless defined $tmpdir;

    What the ... That can't be right.  Okay, maybe the current
    directory is a reasonable last resort, but at the very least
    one should use File::Spec->curdir (change #18956) (instead
    of the UNIXy '') (note that for Mac this cleanup makes a slight
    difference, Mac used before the change cwd(), which gives absolute
    paths, now ":" is relative)

All the tests still work, at least in Unix...

Okay, now to the "cleanup" part: there seems to be nasty code
duplication in the tmpdir()s of File::Spec, and now I created more
with my Cygwin addition...  The differences are annoyingly small:

	- Cygwin checks for $ENV{TMPDIR} /tmp c:/temp (the last just added)
	- Mac checks for $ENV{TMPDIR} and curdir
	- OS/2 checks for @ENV{qw{TMPDIR TEMP TMP}} /tmp /
	- Unix checks for $ENV{TMPDIR} /
	- VMS checks for sys$scratch: $ENV{TMPDIR}
	- Win32 checks for @ENV{qw{TMPDIR TEMP TMP}} SYS:/TEMP C:/temp /tmp /

All check the %ENV entries for taintedness, expect Mac (probably an
oversight).  Unix and VMS do the taintedness check in an "optimized"
way since they assume only one element coming in from the %ENV.

So basically the only real difference in the logic seems to be the
list of directories to check.  So instead of the various platform
specific either inheriting or overriding code of Unix.pm, we would
need something where a higher-level logic would use platform-specific
data.  If there were a common wrapper (the File::Spec::tmpdir,
I assume...) which would first call the directory list checker

	- non-tainted?
	- directory?
	- writeable?

and then the first matching directory would be returned, and if no
matches from the list, return the curdir (this would drop the last
entry from Mac's directory list).

(I don't know the reason for the position of $ENV{TMPDIR} in VMS.)

So ... anyone feel like doing this cleanup job?

-- 
Jarkko Hietaniemi <jhi@iki.fi> http://www.iki.fi/jhi/ "There is this special
biologist word we use for 'stable'.  It is 'dead'." -- Jack Cohen

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About