WordPress.org

Make WordPress Core

Changeset 14811


Ignore:
Timestamp:
05/23/10 05:56:31 (4 years ago)
Author:
dd32
Message:

Ensure that the entire folder structure exists within the $needed_folders array before attempting to create folders. Fixes cases where the Zip file does not contain a node for a folder which contains subfolders without files in the same level. Fixes #13171

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r14800 r14811  
    603603 
    604604    $needed_dirs = array_unique($needed_dirs); 
     605    foreach ( $needed_dirs as $dir ) { 
     606        // Check the parent folders of the folders all exist within the creation array.  
     607        if ( untrailingslashit($to) == $dir ) // Skip over the working directory, We know this exists (or will exist) 
     608            continue; 
     609 
     610        $parent_folder = dirname($dir); 
     611        while ( !empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs) ) { 
     612            $needed_dirs[] = $parent_folder; 
     613            $parent_folder = dirname($parent_folder); 
     614        } 
     615    } 
    605616    asort($needed_dirs); 
    606617 
     
    671682 
    672683    $needed_dirs = array_unique($needed_dirs); 
     684    foreach ( $needed_dirs as $dir ) { 
     685        // Check the parent folders of the folders all exist within the creation array.  
     686        if ( untrailingslashit($to) == $dir ) // Skip over the working directory, We know this exists (or will exist) 
     687            continue; 
     688 
     689        $parent_folder = dirname($dir); 
     690        while ( !empty($parent_folder) && untrailingslashit($to) != $parent_folder && !in_array($parent_folder, $needed_dirs) ) { 
     691            $needed_dirs[] = $parent_folder; 
     692            $parent_folder = dirname($parent_folder); 
     693        } 
     694    } 
    673695    asort($needed_dirs); 
    674696 
    675697    // Create those directories if need be: 
    676698    foreach ( $needed_dirs as $_dir ) { 
    677         if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the Dir exists upon creation failure. Less I/O this way. 
     699        if ( ! $wp_filesystem->mkdir($_dir, FS_CHMOD_DIR) && ! $wp_filesystem->is_dir($_dir) ) // Only check to see if the dir exists upon creation failure. Less I/O this way. 
    678700            return new WP_Error('mkdir_failed', __('Could not create directory.'), $_dir); 
    679701    } 
Note: See TracChangeset for help on using the changeset viewer.