Make WordPress Core

Opened 12 months ago

Closed 7 weeks ago

Last modified 7 weeks ago

#54477 closed defect (bug) (fixed)

wp-cli vague: "Warning: Could not create directory."

Reported by: gunterer's profile gunterer Owned by: audrasjb's profile audrasjb
Milestone: 6.1 Priority: normal
Severity: minor Version: 5.8
Component: Upgrade/Install Keywords: good-first-bug has-patch has-testing-info commit
Focuses: Cc:

Description

originally from
https://github.com/wp-cli/wp-cli/issues/3255#issuecomment-336900561

When using wp-cli the error output from wordpress which states "Could not create directory." should also include the directory that was attempted to create, ideally as an absolute non-relative path name.

This is needed so that users do not have to resort to opening up permissions on all files and directories, even if temporarily.

Attachments (1)

54477.v202204171752.patch (1.2 KB) - added by rsiddharth 7 months ago.

Download all attachments as: .zip

Change History (26)

#1 @SergeyBiryukov
12 months ago

  • Component changed from Text Changes to Upgrade/Install
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 6.0
  • Type changed from feature request to enhancement

Hi there, welcome to WordPress Trac! Thanks for the ticket.

Just noting that there are three different instances of the "Could not create directory" message in core. Indeed, it makes sense to include the directory name in all of them.

#2 follow-up: @n8finch
9 months ago

@gunterer thanks for creating this ticket!

@SergeyBiryukov I'd like to work on this.

#3 in reply to: ↑ 2 @SergeyBiryukov
9 months ago

Replying to n8finch:

I'd like to work on this.

Great! If you submit a GitHub PR and mention this ticket's URL in the description, it will automatically get linked here, see GitHub Pull Requests for Code Review for more details.

#4 @peterwilsoncc
9 months ago

  • Keywords good-first-bug added

Labeling this as a good first bug.

Each appearance of error messages will probably need to change to (pseudo code):

<?php
sprintf(
  __( 'Could not create directory: %s.' ),
  $failed_directory
);

I count five appearances.

#5 @n8finch
8 months ago

@peterwilsoncc thanks! I'll be working on it in the next couple days.

#6 @n8finch
8 months ago

  • Type changed from enhancement to defect (bug)

@SergeyBiryukov I was testing this and can't replicate it.

Here's what I did:

  • Changed the permissions on the wp-plugins directory to 444.
  • ran wp plugin install gutenberg --activate (and I tested several other plugins)
  • Got the following:
Installing the plugin...
Warning: Could not create directory upgrader. "/Users/natefinch/Local Sites/wpcli-bug-fix/app/wordpress-develop/src/wp-content/plugins/gutenberg/"
Plugin installation failed.
Warning: The 'gutenberg' plugin could not be found.
Error: No plugins installed.

Looking at the code for this particular notification, the directory is already in error notification with $remote_destination: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-admin/includes/class-wp-upgrader.php#L591

This is also the case in the other files (wp-admin/includes/file.php and wp-admin/includes/update-core.php).

These were added 8 years ago by Andrew Nacin: https://core.trac.wordpress.org/changeset/25780

Since the error strings already exits with the $filenames, I think this ticket can be closed, or perhaps someone else can check it out.

#7 @rsiddharth
7 months ago

  • Keywords has-patch added; needs-patch removed

On wp plugin install gutenberg, _unzip_file_ziparchive, which gets
indirectly called, has $to set to
/var/www/src/wp-content/upgrade/gutenberg.13.0.0-ox0GNI/.

And $needed_dirs just before the mkdir call looks like:

Array (
            [0] => /var/www/src/wp-content/upgrade/gutenberg.13.0.0-ox0GNI
            [1] => /var/www/src/wp-content/upgrade/gutenberg.13.0.0-ox0GNI/gutenberg
            [2] => /var/www/src/wp-content/upgrade/gutenberg.13.0.0-ox0GNI/gutenberg/build
            .
            .
            .
)

When $_dir is /var/www/src/wp-content/upgrade/gutenberg.13.0.0-ox0GNI
(first item in $needed_dirs), substr( $_dir, strlen( $to ) )
returns an empty string. So, I think that's the issue.

So, if we try to pass full directory to WP_Error instead of the base
directory, it should fix the issue. I've attached the initial version
the patch. See if it looks good.

wp plugin install without the patch:

$ wp plugin install gutenberg
Installing Gutenberg (13.0.0)
Downloading installation package from https://downloads.wordpress.org/plugin/gutenberg.13.0.0.zip...
The authenticity of gutenberg.13.0.0.zip could not be verified as no signature was found.
Unpacking the package...
Warning: Could not create directory.
Warning: The 'gutenberg' plugin could not be found.
Error: No plugins installed.

wp plugin install with the patch (54477.v202204171752.patch):

$ wp plugin install gutenberg
Installing Gutenberg (13.0.0)
Downloading installation package from https://downloads.wordpress.org/plugin/gutenberg.13.0.0.zip...
Using cached file '/home/wp_php/.wp-cli/cache/plugin/gutenberg-13.0.0.zip'...
The authenticity of gutenberg.13.0.0.zip could not be verified as no signature was found.
Unpacking the package...
Warning: Could not create directory. "/var/www/src/wp-content/upgrade/gutenberg.13.0.0-ox0GNI"
Warning: The 'gutenberg' plugin could not be found.
Error: No plugins installed.
Last edited 7 months ago by rsiddharth (previous) (diff)

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


7 months ago

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


7 months ago

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


7 months ago

#11 @SergeyBiryukov
7 months ago

  • Keywords needs-testing added

#12 @costdev
7 months ago

  • Milestone changed from 6.0 to 6.1

With 6.0 RC1 tomorrow, the patch still needs testing. Moving to the 6.1 milestone.

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


3 months ago

#14 @costdev
3 months ago

  • Keywords has-testing-info added; needs-testing removed

Test Report

Patch tested: https://core.trac.wordpress.org/attachment/ticket/54477/54477.v202204171752.patch

Steps to Reproduce or Test

  1. Run sudo chmod 444 wp-content/plugins.
  2. If using the root user, switch to a different user.
  3. 🐞 Run wp plugin install gutenberg.

Expected Results

When reproducing the issue:

  • ❌ The output should read:
Installing Gutenberg (14.0.2)
Downloading installation package from https://downloads.wordpress.org/plugin/gutenberg.VERSION.zip...
Using cached file '/home/USER/.wp-cli/cache/plugin/gutenberg-VERSION.zip'...
Unpacking the package...
Warning: Could not create directory.
Warning: The 'gutenberg' plugin could not be found.
Error: No plugins installed.

When testing a patch to validate it works as expected:

  • ✅ The output should read:
Installing Gutenberg (14.0.2)
Downloading installation package from https://downloads.wordpress.org/plugin/gutenberg.VERSION.zip...
Using cached file '/home/USER/.wp-cli/cache/plugin/gutenberg-VERSION.zip'...
Unpacking the package...
Warning: Could not create directory. "/path/to/site/wp-content/upgrade/gutenberg.14.0.2-yastQK"
Warning: The 'gutenberg' plugin could not be found.
Error: No plugins installed.

Environment

  • Server: Apache (Linux)
  • WordPress: 6.1-alpha-53344-src
  • CLI: WP-CLI
  • OS: Ubuntu
  • Plugins: None activated

Actual Results

When reproducing a bug/defect:

  • ❌ The output did not include the directory path. Issue reproduced.

When testing the bugfix patch:

  • ✅ The output included the directory path. Issue resolved with patch.

#15 follow-up: @costdev
3 months ago

  • Keywords dev-feedback added

@peterwilsoncc I couldn't find the other three appearances you referenced before.

I see the two targeted by 54477.v202204171752.patch.

Aside from that, there are these two instances:

// wp-admin/includes/file.php:1924
return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );

// wp-admin/includes/update-core.php:1524
return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );

However:

  • The latter is planned for removal in #55712.
  • $to . $filename = "Path to destination directory" + The key from WP_Filesystem_*::dirlist, so this doesn't appear to be associated with this issue.

In your opinion, what's the next move for this ticket?

#16 @desrosj
7 weeks ago

Looks like #55712 did indeed make it for 6.1 through [54143].

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


7 weeks ago

#18 @audrasjb
7 weeks ago

  • Keywords needs-refresh added; dev-feedback removed

As per today's bug scrub:

This patch is no longer blocked by ticket #55712 as it was committed with [54143].

However, the patch needs to be refreshed against trunk. Let's keep it in the milestone :)

This ticket was mentioned in PR #3425 on WordPress/wordpress-develop by audrasjb.


7 weeks ago
#19

  • Keywords needs-refresh removed

#20 @audrasjb
7 weeks ago

The above PR refreshes the patch against trunk.

#21 @mukesh27
7 weeks ago

@audrasjb PR #3425 looks good to me and approved.

#22 @audrasjb
7 weeks ago

  • Keywords commit added
  • Owner set to audrasjb
  • Status changed from new to accepted

Self-assigning for commit.

#23 @audrasjb
7 weeks ago

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

In 54442:

Upgrade/Install: Provide dirpath in error messages when _unzip_file_pclzip() cannot create directories.

This changeset ensures the directory path is provided in error messages when _unzip_file_pclzip() is unable to create a directory. This removes substr() which was returning an empty string in some use cases.

Props gunterer, SergeyBiryukov, n8finch, peterwilsoncc, audrasjb, rsiddharth, costdev , desrosj, mukesh27.
Fixes #54477.

#24 in reply to: ↑ 15 @SergeyBiryukov
7 weeks ago

Replying to costdev:

I couldn't find the other three appearances you referenced before.

I see the two targeted by 54477.v202204171752.patch.

Aside from that, there are these two instances:

// wp-admin/includes/file.php:1924
return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );

// wp-admin/includes/update-core.php:1524
return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );

However:

  • The latter is planned for removal in #55712.
  • $to . $filename = "Path to destination directory" + The key from WP_Filesystem_*::dirlist, so this doesn't appear to be associated with this issue.

Right. I think the fifth one is defined in WP_Upgrader::generic_strings() and displayed in ::install_package(), though it looks like it may not be related to this issue either, and [54442] appears to be enough here.

Note: See TracTickets for help on using tickets.