WordPress.org

Make WordPress Core

Changeset 25794


Ignore:
Timestamp:
10/15/13 19:17:56 (3 years ago)
Author:
nacin
Message:

Core Updates: Verify that all files we're about to copy are actually writable, when using the direct transport.

Once we begin to copy core files, all bets are off. This allows us to fail early when we'll otherwise need to stop midway through due to permissions issues, which is a particularly bad problem when only some files have permissions issues.

see #22704.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/update-core.php

    r25793 r25794  
    693693    // Don't copy wp-content, we'll deal with that below 
    694694    $skip = array( 'wp-content' ); 
     695    $check_is_writable = array(); 
    695696 
    696697    // Check to see which files don't really need updating - only available for 3.7 and higher 
     
    703704                if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) === $checksum ) 
    704705                    $skip[] = $file; 
     706                else 
     707                    $check_is_writable[ $file ] = ABSPATH . $file; 
    705708            } 
     709        } 
     710    } 
     711 
     712    // If we're using the direct method, we can predict write failures that are due to permissions. 
     713    if ( $wp_filesystem->method === 'direct' ) { 
     714        $files_writable = array_filter( $check_is_writable, array( $wp_filesystem, 'is_writable' ) ); 
     715        if ( $files_writable !== $check_is_writable ) { 
     716            $files_not_writable = array_diff_key( $check_is_writable, $files_writable ); 
     717            foreach ( $files_not_writable as $relative_file_not_writable => $file_not_writable ) { 
     718                // If the writable check failed, chmod file to 0644 and try again, same as copy_dir(). 
     719                $wp_filesystem->chmod( $file_not_writable, FS_CHMOD_FILE ); 
     720                if ( $wp_filesystem->is_writable( $file_not_writable ) ) 
     721                    unset( $files_not_writable[ $relative_file_not_writable ] ); 
     722            } 
     723 
     724            // Store package-relative paths (the key) of non-writable files in the WP_Error object. 
     725            if ( $files_not_writable ) 
     726                return new WP_Error( 'files_not_writable', __( 'Could not copy file.' ), array_keys( $files_not_writable ) ); 
    706727        } 
    707728    } 
Note: See TracChangeset for help on using the changeset viewer.