Making WordPress.org

Changeset 6061


Ignore:
Timestamp:
10/31/2017 06:42:21 AM (7 years ago)
Author:
dd32
Message:

Plugin Directory: Checksums: Add sha256 checksums alongside md5.
This change also adds the full URL to the ZIP & SVN Source location, which may be an array when a single plugin version can be found within multiple ZIPs.

See #3192

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/zip/class-builder.php

    r6047 r6061  
    1212
    1313    const TMP_DIR = '/tmp/plugin-zip-builder';
    14     const SVN_URL = 'http://plugins.svn.wordpress.org';
     14    const SVN_URL = 'https://plugins.svn.wordpress.org';
    1515    const ZIP_SVN_URL = PLUGIN_ZIP_SVN_URL;
    1616
     
    2424    protected $context    = '';
    2525    protected $stable_tag = '';
     26
     27    // The SVN url of the plugin version being packaged.
     28    protected $plugin_version_svn_url = '';
    2629
    2730    /**
     
    204207        $existing_json_checksum_file = file_exists( $this->checksum_file );
    205208
    206         $this->exec( sprintf(
    207             'cd %s && find . -type f -print0 | sort -z | xargs -0 md5sum 2>&1',
    208             escapeshellarg( $this->tmp_build_dir . '/' . $this->slug )
    209         ), $checksum_output, $return_value );
    210 
    211         if ( $return_value ) {
    212         //  throw new Exception( __METHOD__ . ': Checksum generation failed, return code: ' . $return_value, 503 );
    213         // For now, just silently bail.
    214             return;
    215         }
    216 
    217         $checksums = array();
    218         foreach ( $checksum_output as $line ) {
    219             list( $md5, $filename ) = preg_split( '!\s+!', $line );
    220             $filename = preg_replace( '!^./!', '', $filename );
    221             $checksums[ trim( $filename ) ] = trim( $md5 );
     209        $checksums = array(
     210            'md5' => array(),
     211            'sha256' => array()
     212        );
     213        foreach ( array( 'md5' => 'md5sum', 'sha256' => 'sha256sum' ) as $checksum_type => $checksum_bin ) {
     214            $this->exec( sprintf(
     215                'cd %s && find . -type f -print0 | sort -z | xargs -0 ' . $checksum_bin . ' 2>&1',
     216                escapeshellarg( $this->tmp_build_dir . '/' . $this->slug )
     217            ), $checksum_output, $return_value );
     218
     219            if ( $return_value ) {
     220            //  throw new Exception( __METHOD__ . ': Checksum generation failed, return code: ' . $return_value, 503 );
     221            // TODO For now, just silently keep going.
     222                continue;
     223            }
     224
     225            foreach ( $checksum_output as $line ) {
     226                list( $checksum, $filename ) = preg_split( '!\s+!', $line );
     227                $filename = trim( preg_replace( '!^./!', '', $filename ) );
     228                $checksum = trim( $checksum );
     229                $checksums[ $checksum_type][ $filename ] = $checksum;
     230            }
    222231        }
    223232
     
    225234            'plugin'     => $this->slug,
    226235            'version'    => $plugin_version,
    227             'source_tag' => $this->version,
    228             'zip'        => basename( $this->zip_file ),
    229             'checksums'  => $checksums
     236            'source'     => $this->plugin_version_svn_url,
     237            'zip'        => 'https://downloads.wordpress.org/plugins/' . basename( $this->zip_file ),
     238            'md5'        => $checksums['md5'],
     239            'sha256'     => $checksums['sha256'],
    230240        );
    231241
     
    234244            $existing_json_checksum_file = json_decode( file_get_contents( $this->checksum_file ) );
    235245
    236             if ( $existing_json_checksum_file && ! empty( $existing_json_checksum_file->checksums ) ) {
    237                 foreach ( $existing_json_checksum_file->checksums as $file => $checksum_details ) {
    238 
    239                     if ( ! isset( $json_checksum_file->checksums[ $file ] ) ) {
    240                         // Deleted file, include it in checksums.
    241                         $json_checksum_file->checksums[ $file ] = $checksum_details;
    242 
    243                     } elseif ( $json_checksum_file->checksums[ $file ] != $checksum_details ) {
    244                         // Checksum has changed, include both in the resulting json file.
    245                         if ( is_array( $checksum_details ) ) {
    246                             $checksum_details[] = $json_checksum_file->checksums[ $file ];
    247                             $json_checksum_file->checksums[ $file ] = array_unique( $checksum_details );
    248                         } else {
    249                             $json_checksum_file->checksums[ $file ] = array(
    250                                 $json_checksum_file->checksums[ $file ],
    251                                 $checksum_details
    252                             );
    253                         }
     246            // Sometimes plugin versions exist in multiple tags/zips, include all the SVN urls & ZIP urls
     247            foreach ( array( 'source', 'zip' ) as $maybe_different ) {
     248                if ( !empty( $existing_json_checksum_file->{$maybe_different} ) &&
     249                    $existing_json_checksum_file->{$maybe_different} != $json_checksum_file->{$maybe_different}
     250                ) {
     251                    $json_checksum_file->{$maybe_different} = array_unique( array_merge(
     252                        (array) $existing_json_checksum_file->{$maybe_different},
     253                        (array) $json_checksum_file->{$maybe_different}
     254                    ) );
     255
     256                    // Reduce single arrays back to a string when possible.
     257                    if ( 1 == count( $json_checksum_file->{$maybe_different} ) ) {
     258                        $json_checksum_file->{$maybe_different} = array_shift( $json_checksum_file->{$maybe_different} );
    254259                    }
    255260                }
     261            }
     262
     263            // Combine Checksums from existing files and the new files
     264            foreach ( array( 'md5', 'sha256' ) as $checksum_type ) {
     265                if ( ! $existing_json_checksum_file || empty( $existing_json_checksum_file->{$checksum_type} ) ) {
     266                    continue;
     267                }
     268                $existing_checksums = (array) $existing_json_checksum_file->{$checksum_type}; // Assoc array => Object in JSON
     269                $new_checksums = &$json_checksum_file->{$checksum_type}; // byref to update new array
     270
     271                foreach ( $existing_checksums as $file => $checksums ) {
     272                    if ( ! isset( $new_checksums[ $file ] ) ) {
     273                        // Deleted file, include it in checksums.
     274                        $new_checksums[ $file ] = $existing_checksums[ $file ];
     275
     276                    } elseif ( $new_checksums[ $file ] != $existing_checksums[ $file ] ) {
     277                        // Checksum has changed, include both in the resulting json file.
     278
     279                        $new_checksums[ $file ] = array_unique( array_merge(
     280                            (array) $existing_checksums[ $file ], // May already be an array
     281                            (array) $new_checksums[ $file ]
     282                        ) );
     283                    }
     284                }
     285
    256286            }
    257287        }
     
    303333    protected function export_plugin() {
    304334        if ( 'trunk' == $this->version ) {
    305             $svn_url = self::SVN_URL . "/{$this->slug}/trunk/";
     335            $this->plugin_version_svn_url = self::SVN_URL . "/{$this->slug}/trunk/";
    306336        } else {
    307             $svn_url = self::SVN_URL . "/{$this->slug}/tags/{$this->version}/";
    308         }
     337            $this->plugin_version_svn_url = self::SVN_URL . "/{$this->slug}/tags/{$this->version}/";
     338        }
     339
    309340        $build_dir = "{$this->tmp_build_dir}/{$this->slug}/";
    310341
     
    315346        }
    316347
    317         $res = SVN::export( $svn_url, $build_dir, $svn_params );
     348        $res = SVN::export( $this->plugin_version_svn_url, $build_dir, $svn_params );
    318349        // Handle tags which we store as 0.blah but are in /tags/.blah
    319350        if ( ! $res['result'] && '0.' == substr( $this->version, 0, 2 ) ) {
    320351            $_version = substr( $this->version, 1 );
    321             $svn_url = self::SVN_URL . "/{$this->slug}/tags/{$_version}/";
    322             $res = SVN::export( $svn_url, $build_dir, $svn_params );
     352             $this->plugin_version_svn_url = self::SVN_URL . "/{$this->slug}/tags/{$_version}/";
     353            $res = SVN::export( $this->plugin_version_svn_url, $build_dir, $svn_params );
    323354        }
    324355        if ( ! $res['result'] ) {
Note: See TracChangeset for help on using the changeset viewer.