r35819 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r35818‎ | r35819 | r35820 >
Date:20:28, 3 June 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Revert wfMkdirParents back to old method not using recursive mkdir
* mkdir is affected by umask
* modifying umask is not thread safe
* work around is to use chmod... which the old code already did
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

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

Follow-up revisions

RevisionCommit summaryAuthorDate
r35828Revert r35819 -- broke thumbnailing....brion23:46, 3 June 2008

Status & tagging log