| @@ -236,19 +236,12 @@ | ||
| 236 | 236 | } |
| 237 | 237 | $file_name = $hash . '.' . $ext; |
| 238 | 238 | $file_path = $paths['basedir'] . '/' . $file_name; |
| 239 | 239 | |
| 240 | - /* | |
| 241 | - * Move the file to its destination, once more after re-creating the directory if that | |
| 242 | - * fails. Caching an entity's file races with invalidating that same entity, which deletes | |
| 243 | - * the whole directory: when the delete lands between the two, the move has nowhere to put | |
| 244 | - * the file and the download is lost for no reason. | |
| 245 | - */ | |
| 240 | + // Move file to destination. | |
| 246 | 241 | if ( ! static::get_filesystem()->move( $tmp_file, $file_path, true ) ) { |
| 247 | - if ( ! \wp_mkdir_p( $paths['basedir'] ) || ! static::get_filesystem()->move( $tmp_file, $file_path, true ) ) { | |
| 248 | - \wp_delete_file( $tmp_file ); | |
| 249 | - return false; | |
| 250 | - } | |
| 242 | + \wp_delete_file( $tmp_file ); | |
| 243 | + return false; | |
| 251 | 244 | } |
| 252 | 245 | |
| 253 | 246 | // Optimize image if applicable. |
| 254 | 247 | $max_dimension = $options['max_dimension'] ?? static::get_max_dimension(); |
| @@ -574,9 +567,9 @@ | ||
| 574 | 567 | |
| 575 | 568 | // Method 4: Ensure file extension matches MIME type. |
| 576 | 569 | $ext = \pathinfo( $file_path, PATHINFO_EXTENSION ); |
| 577 | 570 | |
| 578 | - if ( \strtolower( $ext ) !== $expected_ext ) { | |
| 571 | + if ( strtolower( $ext ) !== $expected_ext ) { | |
| 579 | 572 | $new_path = \preg_replace( '/\.[^.]+$/', '.' . $expected_ext, $file_path ); |
| 580 | 573 | if ( empty( $new_path ) || $new_path === $file_path ) { |
| 581 | 574 | $new_path = $file_path . '.' . $expected_ext; |
| 582 | 575 | } |
| @@ -667,14 +660,10 @@ | ||
| 667 | 660 | |
| 668 | 661 | // Handle result. |
| 669 | 662 | $result_path = $result['path'] ?? $file_path; |
| 670 | 663 | |
| 671 | - /* | |
| 672 | - * If the path changed (format conversion), delete the original file. It may already be | |
| 673 | - * gone: invalidating the entity deletes its whole directory, and that can land while this | |
| 674 | - * file is being converted. Deleting it again is not an error worth a diagnostic. | |
| 675 | - */ | |
| 676 | - if ( $result_path !== $file_path && \file_exists( $file_path ) ) { | |
| 664 | + // If path changed (format conversion), delete the original file. | |
| 665 | + if ( $result_path !== $file_path ) { | |
| 677 | 666 | \wp_delete_file( $file_path ); |
| 678 | 667 | } |
| 679 | 668 | |
| 680 | 669 | return $result_path; |