If you look inside of
/wp-admin/includes/update-core.php there is some good info within a comment around line 826.
Here are the steps the upgrader should take...
- Test unzipped location for select files to ensure that unzipped worked.
- Create the .maintenance file in current WordPress base.
- Copy new WordPress directory over old WordPress files.
- Upgrade WordPress to new version.
- Copy all files/folders other than wp-content
- Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR
- Copy any new bundled themes/plugins to their respective locations
- Delete new WordPress directory path.
- Delete .maintenance file.
- Remove old files.
- Delete 'update_core' option.
And to answer your question "Under which circumstances is the file not deleted?"
There are several areas of failure. For instance if PHP times out
before step 6, then you will not be able to access any portion of your
site. Also, since the upgrade will not continue where it left off, you
will not be able to automatically remove old files and remove the
If the copy of the new WordPress over the old fails, then the worse is
that the new WordPress directory will remain.