From c5ccc7cdfa01b562c284f22d7faae2587204ccee Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 16 Jan 2018 06:58:39 +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.0 branch. Fixes #42963 for 4.0. Built from https://develop.svn.wordpress.org/branches/4.0@42474 git-svn-id: http://core.svn.wordpress.org/branches/4.0@42303 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 054549c1a8..2b02af6c45 100644 --- a/wp-admin/includes/update-core.php +++ b/wp-admin/includes/update-core.php @@ -1008,7 +1008,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