From 5018b6595c4fcd21f85d08028e21ec3e661b1214 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 16 Jan 2018 06:52:42 +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.7 branch. Fixes #42963 for 4.7. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@42467 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/update-core.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/update-core.php b/src/wp-admin/includes/update-core.php index 3e6aaa2051..c377953b9e 100644 --- a/src/wp-admin/includes/update-core.php +++ b/src/wp-admin/includes/update-core.php @@ -1084,7 +1084,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