WordPress.org

Make WordPress Core

Opened 11 months ago

Last modified 7 days ago

#50349 new defect (bug)

Plugin Update deletes plugin and showing "could not delete old plugin" message.

Reported by: apedog Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Plugins Keywords:
Focuses: Cc:

Description

I just came across this on my local machine (Windows).

I had a plugin directory open in vscode editor. I had also previously edited one of the files in that plugin (added error_logs in one of the functions for testing). I may or may not have had same file open with further unsaved changes (I don't know at this point).

In the Plugins page I clicked the "update now" in the plugin row (directory was still open in vscode).
The update resolved with a "Could not delete old plugin" error notice. However the plugin was removed and directory is left empty.

Change History (4)

#1 @SergeyBiryukov
11 months ago

I also had this happen a few times when attempting to update a plugin while one of its files was opened in an editor.

I believe this is working as intended though, since the OS doesn't allow for removing a directory with a locked file. What would be a suggested fix here?

#2 @apedog
11 months ago

I'd like to start off by saying that this is not a major issue for me. I ran across this edge-case and figured I'd post a bug report - for the record. This did not impede my work in any meaningful way. Maybe it's an unimportant edge-case, maybe it touches upon a deeper implementation problem - I honestly don't know.

Nonetheless, if this issue is to be addressed:

  1. At the very least the message "Could not delete old plugin" is wrong. The old plugin was deleted. Empty plugin directory was all that remained.
  1. As for "expected" behaviour - my expectation would be that if the update failed, I'd still have the old version in place, and not have the plugin vanish unceremoniously. Or at least some indication that a plugin was removed due to an error (and what the plugin's basename was - allowing the user to troubleshoot). As it stands upon Plugins page refresh - everything appears normal sans the deleted plugin.

I've no idea as to the amount of work that would go into fixing this. Just laying it out.

#3 follow-up: @pbiron
8 days ago

I've also experienced this a number of times on my local dev machine. Also happens (at least in Windows), if you've got a shell open in the plugin directory (or one of it's sub-directories). In fact, probably 95% (or more) of update failures I've experienced over the years on my local were the result of this.

The only way I can think to prevent it would be to check whether any of the files in the directory were opened before starting to try to delete them. However, I don't think there's a reliable way in PHP to check this (that works across OS's and web server configurations).

@apedog Do you remember what version of PHP you were running when this happened to you? I mention that because I just noticed that the PHP manual for unlink() now says that as of PHP 7.3.0:

On Windows, it is now possible to unlink() files with handles in use, while formerly that would fail. However, it is still not possible to re-create the unlinked file, until all handles to it have been closed.

#4 in reply to: ↑ 3 @apedog
7 days ago

Replying to pbiron:

Do you remember what version of PHP you were running when this happened to you?

Nope. Sorry.
I see that I've installed PHP 7.4 almost exactly 12 months ago. And this ticket is from 11 months ago.
But it did take me a while before I fully migrated my environment from 7.2
So this is exactly from that time :(

Note: See TracTickets for help on using tickets.