Followup r61655, add sys_get_temp_dir() support to wfTempDir(), use this in HttpTest...
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 29 Jan 2010 23:52:06 +0000 (23:52 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 29 Jan 2010 23:52:06 +0000 (23:52 +0000)
includes/GlobalFunctions.php
tests/HttpTest.php
tests/bootstrap.php

index 5fa6abf..5ff9629 100644 (file)
@@ -2135,9 +2135,10 @@ function &wfGetMimeMagic() {
 }
 
 /**
- * Tries to get the system directory for temporary files.
- * The TMPDIR, TMP, and TEMP environment variables are checked in sequence,
- * and if none are set /tmp is returned as the generic Unix default.
+ * Tries to get the system directory for temporary files. For PHP >= 5.2.1,
+ * we'll use sys_get_temp_dir(). The TMPDIR, TMP, and TEMP environment
+ * variables are then checked in sequence, and if none are set /tmp is
+ * returned as the generic Unix default.
  *
  * NOTE: When possible, use the tempfile() function to create temporary
  * files to avoid race conditions on file creation, etc.
@@ -2145,6 +2146,9 @@ function &wfGetMimeMagic() {
  * @return String
  */
 function wfTempDir() {
+       if( function_exists( 'sys_get_temp_dir' ) ) {
+               return sys_get_temp_dir();
+       }
        foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
                $tmp = getenv( $var );
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
index 2a1037f..e81c71d 100644 (file)
@@ -32,8 +32,8 @@ class HttpTest extends PhpUnit_Framework_TestCase {
                        $this->markTestIncomplete("This test requires the curl binary at /usr/bin/curl.  If you have curl, please file a bug on this test, or, better yet, provide a patch.");
                }
 
-               $content = tempnam( sys_get_temp_dir(), "" );
-               $headers = tempnam( sys_get_temp_dir(), "" );
+               $content = tempnam( wfTempDir(), "" );
+               $headers = tempnam( wfTempDir(), "" );
                if ( !$content && !$headers ) {
                        die( "Couldn't create temp file!" );
                }
index 3f0e6be..0eec5b2 100644 (file)
@@ -21,18 +21,4 @@ require_once "$IP/includes/ProfilerStub.php";
 require_once "$IP/includes/GlobalFunctions.php";
 require_once "$IP/includes/Hooks.php";
 
-// for php versions before 5.2.1
-if ( !function_exists('sys_get_temp_dir')) {
-  function sys_get_temp_dir() {
-         if( $temp=getenv('TMP') )                return $temp;
-         if( $temp=getenv('TEMP') )            return $temp;
-         if( $temp=getenv('TMPDIR') )    return $temp;
-         $temp=tempnam(__FILE__,'');
-         if (file_exists($temp)) {
-                 unlink($temp);
-                 return dirname($temp);
-         }
-         return null;
-  }
- }