r35833 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35832‎ | r35833 | r35834 >
Date:00:14, 4 June 2008
Author:tstarling
Status:old
Tags:
Comment:
Fix and revert revert of 35819. is_writable() should apply to the parent, not the nonexistent new directory.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1706,7 +1706,54 @@
17071707 return true;
17081708 if( file_exists( $fullDir ) )
17091709 return true;
1710 - return mkdir( str_replace( '/', DIRECTORY_SEPARATOR, $fullDir ), $mode, true );
 1710+
 1711+ # Go back through the paths to find the first directory that exists
 1712+ $currentDir = $fullDir;
 1713+ $createList = array();
 1714+ while ( strval( $currentDir ) !== '' && !file_exists( $currentDir ) ) {
 1715+ # Strip trailing slashes
 1716+ $currentDir = rtrim( $currentDir, '/\\' );
 1717+
 1718+ # Add to create list
 1719+ $createList[] = $currentDir;
 1720+
 1721+ # Find next delimiter searching from the end
 1722+ $p = max( strrpos( $currentDir, '/' ), strrpos( $currentDir, '\\' ) );
 1723+ if ( $p === false ) {
 1724+ $currentDir = false;
 1725+ } else {
 1726+ $currentDir = substr( $currentDir, 0, $p );
 1727+ }
 1728+ }
 1729+
 1730+ if ( count( $createList ) == 0 ) {
 1731+ # Directory specified already exists
 1732+ return true;
 1733+ } elseif ( $currentDir === false ) {
 1734+ # Went all the way back to root and it apparently doesn't exist
 1735+ wfDebugLog( 'mkdir', "Root doesn't exist?\n" );
 1736+ return false;
 1737+ }
 1738+ # Now go forward creating directories
 1739+ $createList = array_reverse( $createList );
 1740+
 1741+ # Is the parent directory writable?
 1742+ if ( $currentDir === '' ) {
 1743+ $currentDir = '/';
 1744+ }
 1745+ if ( !is_writable( $currentDir ) ) {
 1746+ wfDebugLog( 'mkdir', "Not writable: $currentDir\n" );
 1747+ return false;
 1748+ }
 1749+
 1750+ foreach ( $createList as $dir ) {
 1751+ # use chmod to override the umask, as suggested by the PHP manual
 1752+ if ( !mkdir( $dir, $mode ) || !chmod( $dir, $mode ) ) {
 1753+ wfDebugLog( 'mkdir', "Unable to create directory $dir\n" );
 1754+ return false;
 1755+ }
 1756+ }
 1757+ return true;
17111758 }
17121759
17131760 /**

Status & tagging log