From: addshore Date: Wed, 20 Apr 2016 20:39:04 +0000 (+0100) Subject: wfTempDir try harder to get a tmp dir on Windows X-Git-Tag: 1.31.0-rc.0~7006^2 X-Git-Url: https://git.cyclocoop.org/?a=commitdiff_plain;h=96e94d1c905e316658b3dbdc32eb0d5b6ddb12bb;p=lhc%2Fweb%2Fwiklou.git wfTempDir try harder to get a tmp dir on Windows Bug: T44730 Change-Id: If6f93ed50dfd93a1ffe046218058674a2197a626 --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5c42bc26cf..0544c00ddf 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2120,6 +2120,24 @@ function wfTempDir() { return $tmp; } } + + /** + * PHP on Windows will detect C:\Windows\Temp as not writable even though PHP can write to it + * so create a directory within that called 'mwtmp' with a suffix of the user running the + * current process. + * The user is included as if various scripts are run by different users they will likely + * not be able to access each others temporary files. + */ + if ( wfIsWindows() ) { + $tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mwtmp' . '-' . get_current_user(); + if ( !file_exists( $tmp ) ) { + mkdir( $tmp ); + } + if ( file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) { + return $tmp; + } + } + throw new MWException( 'No writable temporary directory could be found. ' . 'Please set $wgTmpDirectory to a writable directory.' ); }