From 4b860b51aefa28cba00f263a3d0ff8c9bb6e75a9 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 16 Jan 2018 06:57:57 +0000 Subject: [PATCH] Upgrade: When deleting old files, if deletion fails attempt to empty the file instead. Props joemcgill, dd32. Merges [42434] to the 4.2 branch. Fixes #42963 for 4.2. Built from https://develop.svn.wordpress.org/branches/4.2@42472 git-svn-id: http://core.svn.wordpress.org/branches/4.2@42301 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/update-core.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/update-core.php b/wp-admin/includes/update-core.php index 04cd780b21..e1b0f9e665 100644 --- a/wp-admin/includes/update-core.php +++ b/wp-admin/includes/update-core.php @@ -1047,7 +1047,11 @@ function update_core($from, $to) { $old_file = $to . $old_file; if ( !$wp_filesystem->exists($old_file) ) continue; - $wp_filesystem->delete($old_file, true); + + // If the file isn't deleted, try writing an empty string to the file instead. + if ( ! $wp_filesystem->delete( $old_file, true ) && $wp_filesystem->is_file( $old_file ) ) { + $wp_filesystem->put_contents( $old_file, '' ); + } } // Remove any Genericons example.html's from the filesystem