#54477 closed defect (bug) (fixed)
wp-cli vague: "Warning: Could not create directory."
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (26)
#1
@
2 years 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
#2
follow-up:
↓ 3
@
21 months ago
@gunterer thanks for creating this ticket!
@SergeyBiryukov I'd like to work on this.
#3
in reply to:
↑ 2
@
21 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
@
21 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.
#6
@
21 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
@
20 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.
This ticket was mentioned in Slack in #core-auto-updates by afragen. View the logs.
20 months ago
This ticket was mentioned in Slack in #core-auto-updates by costdev. View the logs.
20 months ago
This ticket was mentioned in Slack in #core by sergey. View the logs.
20 months ago
#12
@
20 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.
16 months ago
#14
@
15 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
- Run
sudo chmod 444 wp-content/plugins
. - If using the
root
user, switch to a different user. - 🐞 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:
↓ 24
@
15 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 fromWP_Filesystem_*::dirlist
, so this doesn't appear to be associated with this issue.
In your opinion, what's the next move for this ticket?
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
14 months ago
This ticket was mentioned in PR #3425 on WordPress/wordpress-develop by audrasjb.
14 months ago
#19
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/54477
#22
@
14 months ago
- Keywords commit added
- Owner set to audrasjb
- Status changed from new to accepted
Self-assigning for commit
.
#24
in reply to:
↑ 15
@
14 months 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 fromWP_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.
14 months ago
#25
Committed in https://core.trac.wordpress.org/changeset/54442
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.