WordPress.org

Make WordPress Core

Ticket #42196: class-wp-upgrader.patch

File class-wp-upgrader.patch, 1.1 KB (added by sheldonh, 4 years ago)

Demonstration of possible solution

  • wp-admin/includes/class-wp-upgrader.php

    old new  
    300300
    301301                $this->skin->feedback('unpack_package');
    302302
    303                 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
    304 
    305                 //Clean up contents of upgrade directory beforehand.
    306                 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
    307                 if ( !empty($upgrade_files) ) {
    308                         foreach ( $upgrade_files as $file )
    309                                 $wp_filesystem->delete($upgrade_folder . $file['name'], true);
    310                 }
    311 
    312303                // We need a working directory - Strip off any .tmp or .zip suffixes
    313                 $working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
    314 
    315                 // Clean up working directory
    316                 if ( $wp_filesystem->is_dir($working_dir) )
    317                         $wp_filesystem->delete($working_dir, true);
     304                $working_dir = wp_tempnam(basename( basename( $package, '.tmp' ), '.zip' ));
     305                $wp_filesystem->delete($working_dir, true);
     306                wp_mkdir_p($working_dir);
    318307
    319308                // Unzip package to working directory
    320309                $result = unzip_file( $package, $working_dir );