| 212 | 212 | |
| 213 | 213 | $skip_bad_files = array(); |
| 214 | 214 | $checksums = array(); |
| 215 | 215 | foreach ( array( |
| 216 | 216 | 'md5' => 'md5sum', |
| 217 | 217 | 'sha256' => 'sha256sum', |
| 218 | 218 | ) as $checksum_type => $checksum_bin ) { |
| 219 | 219 | $checksum_output = array(); |
| 220 | 220 | $this->exec( sprintf( |
| 221 | 221 | 'cd %s && find . -type f -print0 | sort -z | xargs -0 ' . $checksum_bin . ' 2>&1', |
| 222 | 222 | escapeshellarg( $this->tmp_build_dir . '/' . $this->slug ) |
| 223 | 223 | ), $checksum_output, $return_value ); |
| 224 | 224 | |
| 225 | 225 | if ( $return_value ) { |
| 226 | 226 | // throw new Exception( __METHOD__ . ': Checksum generation failed, return code: ' . $return_value, 503 ); |
| 265 | 269 | // Sometimes plugin versions exist in multiple tags/zips, include all the SVN urls & ZIP urls |
| 266 | 270 | foreach ( array( 'source', 'zip' ) as $maybe_different ) { |
| 267 | 271 | if ( ! empty( $existing_json_checksum_file->{$maybe_different} ) && |
| 268 | 272 | $existing_json_checksum_file->{$maybe_different} != $json_checksum_file->{$maybe_different} |
| 269 | 273 | ) { |
| 270 | 274 | $json_checksum_file->{$maybe_different} = array_unique( array_merge( |
| 271 | 275 | (array) $existing_json_checksum_file->{$maybe_different}, |
| 272 | 276 | (array) $json_checksum_file->{$maybe_different} |
| 273 | 277 | ) ); |
| 274 | 278 | |
| 275 | 279 | // Reduce single arrays back to a string when possible. |
| 276 | 280 | if ( 1 == count( $json_checksum_file->{$maybe_different} ) ) { |
| 277 | 281 | $json_checksum_file->{$maybe_different} = array_shift( $json_checksum_file->{$maybe_different} ); |
| 278 | 282 | } |
| 279 | 283 | } |
| 280 | 284 | } |
| 281 | 285 | |
| 282 | 286 | // Combine Checksums from existing files and the new files |
| 283 | 287 | foreach ( $existing_json_checksum_file->files as $file => $checksums ) { |
| 284 | 288 | |
| 285 | 289 | if ( ! isset( $json_checksum_file->files[ $file ] ) ) { |
| 286 | 290 | if ( isset( $skip_bad_files[ $file ] ) ) { |
| 287 | 291 | // See https://meta.trac.wordpress.org/ticket/3335 |
| 288 | 292 | // This is a partial filename, which shouldn't have been in the checksums. |
| 289 | 293 | continue; |
| 290 | 294 | } |
| 291 | 295 | |
| 292 | 296 | // Deleted file, use existing checksums. |
| 293 | 297 | $json_checksum_file->files[ $file ] = $checksums; |
| 294 | 298 | |
| 295 | 302 | } elseif ( $checksums !== $json_checksum_file->files[ $file ] ) { |
| 296 | 303 | // Checksum has changed, include both in the resulting json file. |
| 297 | 304 | foreach ( array( 'md5', 'sha256' ) as $checksum_type ) { |
| 298 | 305 | $json_checksum_file->files[ $file ][ $checksum_type ] = array_unique( array_merge( |
| 299 | 306 | (array) $checksums->{$checksum_type}, // May already be an array |
| 300 | 307 | (array) $json_checksum_file->files[ $file ][ $checksum_type ] |
| 301 | 308 | ) ); |
| 302 | 309 | |
| 303 | 310 | // Reduce single arrays back to a string when possible. |
| 304 | 311 | if ( 1 == count( $json_checksum_file->files[ $file ][ $checksum_type ] ) ) { |
| 305 | 312 | $json_checksum_file->files[ $file ][ $checksum_type ] = array_shift( $json_checksum_file->files[ $file ][ $checksum_type ] ); |
| 306 | 313 | } |
| 307 | 314 | } |
| 308 | 315 | } |
| 309 | 316 | } |