WordPress.org

Make WordPress Core

Ticket #25576: 25576.diff

File 25576.diff, 2.6 KB (added by dd32, 6 years ago)
  • src/wp-admin/includes/file.php

     
    601601        if ( true !== $zopen )
    602602                return new WP_Error('incompatible_archive', __('Incompatible Archive.'));
    603603
     604        $uncompressed_size = 0;
     605
    604606        for ( $i = 0; $i < $z->numFiles; $i++ ) {
    605607                if ( ! $info = $z->statIndex($i) )
    606608                        return new WP_Error( 'stat_failed_ziparchive', __( 'Could not retrieve file from archive.' ) );
     
    608610                if ( '__MACOSX/' === substr($info['name'], 0, 9) ) // Skip the OS X-created __MACOSX directory
    609611                        continue;
    610612
     613                $uncompressed_size += $info['size'];
     614
    611615                if ( '/' == substr($info['name'], -1) ) // directory
    612616                        $needed_dirs[] = $to . untrailingslashit($info['name']);
    613617                else
    614618                        $needed_dirs[] = $to . untrailingslashit(dirname($info['name']));
    615619        }
    616620
     621        $available_space = disk_free_space( WP_CONTENT_DIR );
     622        if ( $uncompressed_size > $available_space )
     623                return new WP_Error( 'disk_full_preupgrade', sprintf( __( "There isn't enough disk space available at present to update WordPress. WordPress requires at least %s disk space, and you unfortunately only have %s available." ), size_format( $uncompressed_size ), size_format( $available_space ) ) );
     624
    617625        $needed_dirs = array_unique($needed_dirs);
    618626        foreach ( $needed_dirs as $dir ) {
    619627                // Check the parent folders of the folders all exist within the creation array.
     
    693701        if ( 0 == count($archive_files) )
    694702                return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
    695703
     704        $uncompressed_size = 0;
     705
    696706        // Determine any children directories needed (From within the archive)
    697707        foreach ( $archive_files as $file ) {
    698708                if ( '__MACOSX/' === substr($file['filename'], 0, 9) ) // Skip the OS X-created __MACOSX directory
    699709                        continue;
    700710
     711                $uncompressed_size += $file['size'];
     712
    701713                $needed_dirs[] = $to . untrailingslashit( $file['folder'] ? $file['filename'] : dirname($file['filename']) );
    702714        }
    703715
     716        $available_space = disk_free_space( WP_CONTENT_DIR );
     717        if ( $uncompressed_size > $available_space )
     718                return new WP_Error( 'disk_full_preupgrade', sprintf( __( "There isn't enough disk space available at present to update WordPress. WordPress requires at least %s disk space, and you unfortunately only have %s available." ), size_format( $uncompressed_size ), size_format( $available_space ) ) );
     719
    704720        $needed_dirs = array_unique($needed_dirs);
    705721        foreach ( $needed_dirs as $dir ) {
    706722                // Check the parent folders of the folders all exist within the creation array.