Move win_is_writable() from wp-admin/includes to wp-includes so that it's always available for get_temp_dir(). Fixes #20778

git-svn-id: http://core.svn.wordpress.org/trunk@22009 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2012-09-26 05:08:26 +00:00
parent 079afa8ce2
commit a41af6219a
2 changed files with 30 additions and 30 deletions

View File

@ -523,36 +523,6 @@ function saveDomDocument($doc, $filename) {
fclose($fp);
}
/**
* Workaround for Windows bug in is_writable() function
*
* @since 2.8.0
*
* @param string $path
* @return bool
*/
function win_is_writable( $path ) {
/* will work in despite of Windows ACLs bug
* NOTE: use a trailing slash for folders!!!
* see http://bugs.php.net/bug.php?id=27609
* see http://bugs.php.net/bug.php?id=30931
*/
if ( $path[strlen( $path ) - 1] == '/' ) // recursively return a temporary file path
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');
else if ( is_dir( $path ) )
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
// check tmp file for read/write capabilities
$should_delete_tmp_file = !file_exists( $path );
$f = @fopen( $path, 'a' );
if ( $f === false )
return false;
fclose( $f );
if ( $should_delete_tmp_file )
unlink( $path );
return true;
}
/**
* Display the default admin color scheme picker (Used in user-edit.php)
*

View File

@ -1408,6 +1408,36 @@ function get_temp_dir() {
return $temp;
}
/**
* Workaround for Windows bug in is_writable() function
*
* @since 2.8.0
*
* @param string $path
* @return bool
*/
function win_is_writable( $path ) {
/* will work in despite of Windows ACLs bug
* NOTE: use a trailing slash for folders!!!
* see http://bugs.php.net/bug.php?id=27609
* see http://bugs.php.net/bug.php?id=30931
*/
if ( $path[strlen( $path ) - 1] == '/' ) // recursively return a temporary file path
return win_is_writable( $path . uniqid( mt_rand() ) . '.tmp');
else if ( is_dir( $path ) )
return win_is_writable( $path . '/' . uniqid( mt_rand() ) . '.tmp' );
// check tmp file for read/write capabilities
$should_delete_tmp_file = !file_exists( $path );
$f = @fopen( $path, 'a' );
if ( $f === false )
return false;
fclose( $f );
if ( $should_delete_tmp_file )
unlink( $path );
return true;
}
/**
* Get an array containing the current upload directory's path and url.
*