From: Niklas Laxström Date: Tue, 3 Jun 2008 20:28:28 +0000 (+0000) Subject: * Revert wfMkdirParents back to old method not using recursive mkdir X-Git-Tag: 1.31.0-rc.0~47201 X-Git-Url: https://git.cyclocoop.org//%22?a=commitdiff_plain;h=30831d808b335c40b37fa75a6239f096f2d5d605;p=lhc%2Fweb%2Fwiklou.git * 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 --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 446c31b48a..6bd1fb8bb3 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1705,7 +1705,48 @@ function wfMkdirParents( $fullDir, $mode = 0777 ) { return true; if( file_exists( $fullDir ) ) return true; - return mkdir( str_replace( '/', DIRECTORY_SEPARATOR, $fullDir ), $mode, true ); + + # Go back through the paths to find the first directory that exists + $currentDir = $fullDir; + $createList = array(); + while ( strval( $currentDir ) !== '' && !file_exists( $currentDir ) ) { + # Strip trailing slashes + $currentDir = rtrim( $currentDir, '/\\' ); + + # Add to create list + $createList[] = $currentDir; + + # Find next delimiter searching from the end + $p = max( strrpos( $currentDir, '/' ), strrpos( $currentDir, '\\' ) ); + if ( $p === false ) { + $currentDir = false; + } else { + $currentDir = substr( $currentDir, 0, $p ); + } + } + + if ( count( $createList ) == 0 ) { + # Directory specified already exists + return true; + } elseif ( $currentDir === false ) { + # Went all the way back to root and it apparently doesn't exist + return false; + } + + # Now go forward creating directories + $createList = array_reverse( $createList ); + foreach ( $createList as $dir ) { + # Check first to avoid spamming with warnings + if ( !is_writable( $dir ) ) { + return false; + } + # use chmod to override the umask, as suggested by the PHP manual + if ( !mkdir( $dir, $mode ) || !chmod( $dir, $mode ) ) { + wfDebugLog( 'mkdir', "Unable to create directory $dir\n" ); + return false; + } + } + return true; } /**