From: Tim Starling Date: Wed, 4 Jun 2008 00:14:13 +0000 (+0000) Subject: Fix and revert revert of 35819. is_writable() should apply to the parent, not the... X-Git-Tag: 1.31.0-rc.0~47190 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/categories/modifier.php?a=commitdiff_plain;h=b5c2e1b4edea86b01a499aaa84d6e6018a5bc943;p=lhc%2Fweb%2Fwiklou.git Fix and revert revert of 35819. is_writable() should apply to the parent, not the nonexistent new directory. --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 95a181981d..5828200188 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1706,7 +1706,54 @@ 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 + wfDebugLog( 'mkdir', "Root doesn't exist?\n" ); + return false; + } + # Now go forward creating directories + $createList = array_reverse( $createList ); + + # Is the parent directory writable? + if ( $currentDir === '' ) { + $currentDir = '/'; + } + if ( !is_writable( $currentDir ) ) { + wfDebugLog( 'mkdir', "Not writable: $currentDir\n" ); + return false; + } + + foreach ( $createList as $dir ) { + # 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; } /**