Skip to content

Commit d1e030f

Browse files
Copilotswissspidy
andcommitted
Change order: clean up old_files first, then handle checksums
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 6443609 commit d1e030f

1 file changed

Lines changed: 3 additions & 41 deletions

File tree

src/Core_Command.php

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,14 +1794,15 @@ private function cleanup_extra_files( $version_from, $version_to, $locale, $inse
17941794
return;
17951795
}
17961796

1797+
// Always clean up files from WordPress core's $_old_files list first
1798+
$this->cleanup_old_files();
1799+
17971800
$old_checksums = self::get_core_checksums( $version_from, $locale ?: 'en_US', $insecure );
17981801
$new_checksums = self::get_core_checksums( $version_to, $locale ?: 'en_US', $insecure );
17991802

18001803
$has_checksums = is_array( $old_checksums ) && is_array( $new_checksums );
18011804

18021805
if ( ! $has_checksums ) {
1803-
// When checksums are not available, use WordPress core's $_old_files list
1804-
$this->cleanup_old_files();
18051806
return;
18061807
}
18071808

@@ -1895,16 +1896,11 @@ private function cleanup_extra_files( $version_from, $version_to, $locale, $inse
18951896
WP_CLI::log( 'No files found that need cleaning up.' );
18961897
}
18971898
}
1898-
1899-
// Additionally, clean up files from $_old_files that are not in checksums
1900-
// These should be deleted unconditionally as they are known old files
1901-
$this->cleanup_old_files_not_in_checksums( $old_checksums, $new_checksums );
19021899
}
19031900

19041901
/**
19051902
* Clean up old files using WordPress core's $_old_files list.
19061903
*
1907-
* This method is used when checksums are not available for version comparison.
19081904
* It unconditionally deletes files from the $_old_files global array maintained by WordPress core.
19091905
*/
19101906
private function cleanup_old_files() {
@@ -1925,40 +1921,6 @@ private function cleanup_old_files() {
19251921
}
19261922
}
19271923

1928-
/**
1929-
* Clean up old files from $_old_files that are not tracked in checksums.
1930-
*
1931-
* This method is used as a supplement when checksums ARE available.
1932-
* It unconditionally deletes files from $_old_files that are not present in either
1933-
* the old or new checksums, as these files cannot be verified for modifications.
1934-
*
1935-
* @param array $old_checksums Old checksums array.
1936-
* @param array $new_checksums New checksums array.
1937-
*/
1938-
private function cleanup_old_files_not_in_checksums( $old_checksums, $new_checksums ) {
1939-
$old_files = $this->get_old_files_list();
1940-
if ( empty( $old_files ) ) {
1941-
return;
1942-
}
1943-
1944-
// Combine all files from both checksum arrays
1945-
$all_checksum_files = array_merge( array_keys( $old_checksums ), array_keys( $new_checksums ) );
1946-
$all_checksum_files = array_unique( $all_checksum_files );
1947-
1948-
// Find files in $_old_files that are not in checksums
1949-
$files_to_remove = array_diff( $old_files, $all_checksum_files );
1950-
1951-
if ( empty( $files_to_remove ) ) {
1952-
return;
1953-
}
1954-
1955-
$count = $this->remove_old_files_from_list( $files_to_remove );
1956-
1957-
if ( $count ) {
1958-
WP_CLI::log( number_format( $count ) . ' additional old files cleaned up.' );
1959-
}
1960-
}
1961-
19621924
/**
19631925
* Get the list of old files from WordPress core.
19641926
*

0 commit comments

Comments
 (0)