WordPress.org

Make WordPress Core

Ticket #53705: avoid-corrupting-concurrent-plugin-upgrades.diff

File avoid-corrupting-concurrent-plugin-upgrades.diff, 839 bytes (added by bpayton, 3 months ago)

Patch to avoid conflicts by only deleting older, leftover upgrade files

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

    diff --git a/wp-admin/includes/class-wp-upgrader.php b/wp-admin/includes/class-wp-upgrader.php
    index e456191..26f9b92 100644
    a b class WP_Upgrader { 
    311311                // Clean up contents of upgrade directory beforehand.
    312312                $upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
    313313                if ( ! empty( $upgrade_files ) ) {
     314                        $max_cleanup_mtime = time() - DAY_IN_SECONDS;
    314315                        foreach ( $upgrade_files as $file ) {
    315                                 $wp_filesystem->delete( $upgrade_folder . $file['name'], true );
     316                                // Avoid deleting newer files in case they are from concurrent upgrades
     317                                if ( $wp_filesystem->mtime( $upgrade_folder . $file['name'] ) < $max_cleanup_mtime ) {
     318                                        $wp_filesystem->delete( $upgrade_folder . $file['name'], true );
     319                                }
    316320                        }
    317321                }
    318322