Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#54543 closed defect (bug) (fixed)

Updating Hello Dolly after upgrading 5.0.14 > 5.9.0 Beta 1 fails

Reported by: costdev's profile costdev Owned by: hellofromtonya's profile hellofromTonya
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.9
Component: Upgrade/Install Keywords: has-testing-info has-patch commit
Focuses: Cc:

Description (last modified by costdev)

Environment

OS: Windows 10 (Local by Flywheel)
PHP: 7.4.1 (also on 7.3.5 and 5.6.39)
Server: Apache (also tested with NGINX)
Database: MariaDB 10.4.10
Browser: Chrome 96.0.4664.45
Plugins: Rollback Core and WordPress Beta Tester.

Steps to reproduce

  1. Install WordPress 5.8.2 using Local by Flywheel.
  2. Install the Rollback Core and WordPress Beta Tester plugins.
  3. Navigate to Tools > Rollback Core.
  4. Select 5.0.14 from the dropdown menu and click "Rollback".
  5. Click "Re-install version 5.0.14".
  6. In Local by Flywheel, click the arrow beside your site's path.
  7. Navigate to app/public/wp-content/plugins.
  8. If hello.php exists, skip to step 13.
  9. If hello-dolly directory exists, delete it and proceed to step 11.
  10. If neither hello.php nor the hello-dolly directory exist, proceed to step 11.
  11. Download a copy of WordPress 5.0.14 from here.
  12. Extract hello.php into app/public/wp-content/plugins.
  13. Navigate to Tools -> Beta Testing.
  14. Click "Bleeding Edge" and click "Save".
  15. Click "Beta/RC Only" and click "Save".
  16. Navigate to "Dashboard > Updates".
  17. Run the core update.
  18. Navigate to Appearance > Plugins.
  19. Click "Update now" for Hello Dolly.

You should see this error: Update failed: Could not create directory.

Change History (21)

#1 @costdev
3 years ago

  • Keywords has-testing-info added

#2 @hellofromTonya
3 years ago

  • Component changed from Plugins to Upgrade/Install
  • Milestone changed from Awaiting Review to 5.9

Hello @costdev,

Thanks for reporting this issue. Updating the ticket info including pulling it into 5.9 for investigation and moving it to Upgrade/Install component as it may be related to other upgrade work done in the 5.9 cycle.

Extra information you shared on Slack when updating a single site from 5.0.14 to 5.9.0 Beta 1 via the Beta Tester plugin:

Single-site 5.0.14 -> 5.9.0 Beta 1 via beta tester

  • Can't update pre-existing Hello Dolly plugin.
  • "Update failed: Could not create directory."
  • Site Health shows the directory is writable.

#3 @hellofromTonya
3 years ago

@costdev can you share the following?

  • the error or notification message(s)
  • debug log
  • list of installed plugins

These can help contributors investigate.

#4 @costdev
3 years ago

Site Health Log

Installed Plugins

  • Akismet 4.1 (not activated)
  • Hello Dolly 1.7.1 (not activated)
  • WordPress Beta Tester 3.1.4 (activated)

Errors/Notices

  • Update failed: Could not create directory. after clicking "update now" for Hello Dolly.

debug.log

  • No entries for the update failure.

Other logs

  • DevTools > Network shows this response from admin-ajax.php.
{
  "success": false,
  "data": {
    "update": "plugin",
    "slug": "hello-dolly",
    "oldVersion": "Version 1.7.1",
    "newVersion": "",
    "plugin": "hello.php",
    "pluginName": "Hello Dolly",
    "debug": [
      "Downloading update from https://downloads.wordpress.org/plugin/hello-dolly.1.7.2.zip…",
      "The authenticity of hello-dolly.1.7.2.zip could not be verified as no signature was found.",
      "Unpacking the update…",
      "Installing the latest version…",
      "Removing the old version of the plugin…",
      "Could not create directory. <path>/wp-content/plugins/hello-dolly/",
      "Plugin update failed."
    ],
    "errorCode": "mkdir_failed_destination",
    "errorMessage": "Could not create directory."
  }
}

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


3 years ago

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


3 years ago

#7 @Boniu91
3 years ago

I wasn't able to reproduce it, although I used WP Downgrade | Specific Core Version plugin.

Test Report

Env

  • WordPress 5.0.14 and 5.9-beta1
  • Ubuntu 20.04.2 LTS server
  • Theme: Twenty Twenty One
  • Plugin: WP Downgrade | Beta Tester

Steps to test

  1. Remove Hello Dolly plugin
  2. Downgrade to 5.0.14 WP version
  3. Install Hello Dolly related to this version (1.7.1)
  4. Update to 5.9-beta1 version of WP
  5. Update Hello Dolly plugin

Plugin updated, it's inside the directory

#8 @costdev
3 years ago

  • Description modified (diff)
  • Summary changed from Updating Hello Dolly after upgrading 5.0.4 > 5.9.0 Beta 1 fails to Updating Hello Dolly after upgrading 5.0.14 > 5.9.0 Beta 1 fails

#9 @costdev
3 years ago

Update

This is where it fails.

The error is:

PHP Warning:  mkdir(): No such file or directory in  <path>wp-admin\includes\class-wp-filesystem-direct.php on line 545
PHP Stack trace:
PHP   1. {main}()  <path>wp-admin\admin-ajax.php:0
PHP   2. do_action()  <path>wp-admin\admin-ajax.php:187
PHP   3. WP_Hook->do_action()  <path>wp-includes\plugin.php:470
PHP   4. WP_Hook->apply_filters()  <path>wp-includes\class-wp-hook.php:327
PHP   5. wp_ajax_update_plugin()  <path>wp-includes\class-wp-hook.php:303
PHP   6. Plugin_Upgrader->bulk_upgrade()  <path>wp-admin\includes\ajax-actions.php:4487
PHP   7. Plugin_Upgrader->run()  <path>wp-admin\includes\class-plugin-upgrader.php:354
PHP   8. Plugin_Upgrader->install_package()  <path>wp-admin\includes\class-wp-upgrader.php:837
PHP   9. WP_Filesystem_Direct->mkdir()  <path>wp-admin\includes\class-wp-upgrader.php:629
PHP  10. mkdir()  <path>wp-admin\includes\class-wp-filesystem-direct.php:545

The path being sent is:

<root>/wp-content/plugins/hello-dolly

I've tried:

  • adding a trailing slash (this is specifically removed earlier in the above method, so it was a test of curiosity).
  • converting the slashes to <root>\wp-content\plugins\hello-dolly in line with Windows filesystems.

The error still occurs.

I then tried this:

mkdir( $path, FS_CHMOD_DIR, true )

The first two arguments don't make the difference. The third argument enables recursive creation of directories. This works, but it also deletes everything else that's in the wp-content/plugins directory.

Investigation ongoing.

Last edited 3 years ago by costdev (previous) (diff)

This ticket was mentioned in PR #2019 on WordPress/wordpress-develop by costdev.


3 years ago
#10

  • Keywords has-patch added

Older versions of Hello Dolly are stored in wp-content/plugins/hello.php.

[51815] introduced the creation of a temporary backup of plugins before updating.

The move() (and later, move_dir()) call) uses a $src parameter.
For Hello Dolly, this is <path>/wp-contents/plugins/. - note the period at the end.
For users on Linux and Mac, this doesn't appear to cause any problems.
However, on Windows, the move causes the plugins folder to be moved.

This PR negates the move if the plugin is in the plugins directory.
N.B. All plugins should be in their own directory (i.e. wp-content/plugins/<plugin_dir>).

Trac ticket: https://core.trac.wordpress.org/ticket/54543

#11 @costdev
3 years ago

PR submitted and ready for review.

Tested with hello.php in wp-content/plugins/.
This now updates successfully and is placed in wp-content/plugins/hello-dolly/ as expected.

Tested with these plugins that are correctly stored in wp-content/plugins/slug/:

  • Akismet
  • Core Rollback
  • WooCommerce
  • WordPress SEO (Yoast)

All continue to update successfully.

Note to testers:
This appears to be a Windows-specific issue, so the original issue can only be reproduced on Windows.
However, please do test the PR on other operating systems to ensure there is no regression.

Last edited 3 years ago by costdev (previous) (diff)

This ticket was mentioned in Slack in #core-test by boniu91. View the logs.


3 years ago

#13 @hellofromTonya
3 years ago

  • Owner set to hellofromTonya
  • Status changed from new to reviewing

Self assigning for testing and review.

#14 @hellofromTonya
3 years ago

  • Keywords commit added; needs-testing removed

Test Report

Env:

  • OS: macOS Big Sur
  • Localhost: Local and wp-env (tested on both)
  • Theme: TT1
  • Plugins: Beta Tester (activated), Akismet Anti-Spam (deactivated), Hello Dolly (deactivated)
  • Browser: Chrome, Edge, Safari, and Firefox

Steps

  1. Upgraded to 5.9 nightly
  2. Made sure wp-content/plugins/hello.php file exists
  3. Opened the file and changed Version to 1.5 (this triggers the update notice)
  4. Go to Plugins interface
  5. Under Hello Dolly (in the "There is a new version of Hello Dolly available. View version 1.7.2 details or update now." message) click "update now" link
  6. Open filesystem viewer whether in your favorite IDE/editor or app like Finder
  7. Navigate to wp-content/plugins folder

Expected behavior:

  • wp-content/plugins/hello.php file is no longer there (removed)
  • wp-content/plugins/hello-dolly folder and its files are now there (new)
  • In Plugins interface, Hello Dolly should show 1.7.2 as its version
  • No errors in the error or debug log
  1. Move wp-content/plugins/hello-dolly/hello.php file back to wp-content/plugins folder and delete the wp-content/plugins/hello-dolly/ folder
  2. Change the version number again (like in step 3 above)
  3. Activate the plugin
  4. Update the plugin by clicking the "update now" link

Expected behavior:

  • Same as above
  • And the plugin should remain activated

Test Results

Worked as expected in all testing steps.

Exception: Before and after applying the patch, I get a PHP Warning for rename() when using Local:

[07-Dec-2021 15:07:54 UTC] PHP Warning:  rename(/var/tmp/hello-dolly.1.7.2-rbrmHB.tmp,hello-dolly.1.7.2.zip): Operation not permitted in ../app/public/wp-admin/includes/file.php on line 1201
[07-Dec-2021 15:07:54 UTC] PHP Stack trace:
[07-Dec-2021 15:07:54 UTC] PHP   1. {main}() ../app/public/wp-admin/admin-ajax.php:0
[07-Dec-2021 15:07:54 UTC] PHP   2. do_action() ../app/public/wp-admin/admin-ajax.php:187
[07-Dec-2021 15:07:54 UTC] PHP   3. WP_Hook->do_action() ../app/public/wp-includes/plugin.php:474
[07-Dec-2021 15:07:54 UTC] PHP   4. WP_Hook->apply_filters() ../app/public/wp-includes/class-wp-hook.php:331
[07-Dec-2021 15:07:54 UTC] PHP   5. wp_ajax_update_plugin() ../app/public/wp-includes/class-wp-hook.php:307
[07-Dec-2021 15:07:54 UTC] PHP   6. Plugin_Upgrader->bulk_upgrade() ../app/public/wp-admin/includes/ajax-actions.php:4487
[07-Dec-2021 15:07:54 UTC] PHP   7. Plugin_Upgrader->run() ../app/public/wp-admin/includes/class-plugin-upgrader.php:354
[07-Dec-2021 15:07:54 UTC] PHP   8. Plugin_Upgrader->download_package() ../app/public/wp-admin/includes/class-wp-upgrader.php:779
[07-Dec-2021 15:07:54 UTC] PHP   9. download_url() ../app/public/wp-admin/includes/class-wp-upgrader.php:309
[07-Dec-2021 15:07:54 UTC] PHP  10. rename() ../app/public/wp-admin/includes/file.php:1201

This warning is not related to the patch in this ticket.

The warning does not appear when using wp-env.

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


3 years ago

#16 @hellofromTonya
3 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 52337:

Upgrade/Install: Fix moving plugins folder in WP_Upgrader:: move_to_temp_backup_dir().

[51815] introduced the creation of a temporary backup of plugins before updating.

The move() (and later, move_dir()) call) uses a $src parameter.
For Hello Dolly, this is <path>/wp-contents/plugins/. (note the period at the end).

For users on Linux and Mac, this doesn't appear to cause any problems.
However, on Windows, the move causes the plugins folder to be moved which then causes a failure when attempting to call mkdir().

This commit skips any plugin whose slug is '.' as this slug results in the $src value ending in a period.

Follow-up to [51815].

Props costdev, boniu91, hellofromTonya.
Fixes #54543.

This ticket was mentioned in Slack in #core-auto-updates by hellofromtonya. View the logs.


3 years ago

This ticket was mentioned in Slack in #core-auto-updates by hellofromtonya. View the logs.


3 years ago

This ticket was mentioned in Slack in #core-auto-updates by peterwilsoncc. View the logs.


3 years ago

#21 @peterwilsoncc
3 years ago

In 52351:

Upgrade/install: Revert upgrader rollback features.

Revert the rollback features introduced for theme and plugin upgrades during the WordPress 5.9 cycle. A bug (suspected to be in third party virtualisation software) causes the upgrades to fail consistently on some set ups. The revert is to allow contributors further time to investigate mitigation options.

Reverts [52337], [52289], [52284], [51951], [52192], [51902], [51899], [51898], [51815].

Props pbiron, dlh, peterwilsoncc, galbaras, SergeyBiryukov, afragen, costdev, bronsonquick, aristath, noisysocks, desrosj, TobiasBg, hellofromTonya, francina, Boniu91.
See #54543, #54166, #51857.

Note: See TracTickets for help on using tickets.