Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#12113 closed defect (bug) (duplicate)

Plugin, theme, etc install issue (Could not create directory.)

Reported by: jfine's profile jfine Owned by: dd32's profile dd32
Milestone: Priority: normal
Severity: normal Version: 2.9.1
Component: Filesystem API Keywords: Plugin, theme, could not create directory
Focuses: Cc:

Description

PHP: PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2 - Running as FastCGI
Wordpress: 2.9.1 clean install
OS: Ubuntu 8.04 LTS Server

After digging through the source the issue appears to be with how the $remote_destination is found. If $remote_destination ends with a trailing slash the call to mkdir() will fail.

This issue appears to be a partially a PHP issue as indicated by the two examples:
http://us3.php.net/manual/en/function.mkdir.php#73848
http://stackoverflow.com/questions/1399174/php-mkdir-recursive-true-skips-last-directory

Never the less the wordpress mkdir() function should be patched to check for a trailing slash and if found remove it.

Example failure (notice the trailing slash on the directory path):

Installing Plugin: Contact Form 7 2.1.1
Downloading install package from http://downloads.wordpress.org/plugin/contact-form-7.2.1.1.zip.

Unpacking the package.

Installing the plugin.

Could not create directory. /var/www/vhosts/bizplancompetitions.com/httpdocs/wp-content/plugins/contact-form-7/

Plugin Install Failed.

Example fix (patch for wp-admin/includes/class-wp-filesystem-direct.php):

--- class-wp-filesystem-direct.php	2010-02-02 00:27:28.000000000 +0000
+++ class-wp-filesystem-direct.php.new	2010-02-02 00:28:36.000000000 +0000
@@ -280,6 +280,9 @@
 	}
 
 	function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
+                if( preg_match('/^(.+)\/+$/', $path, $matches) )
+                        $path = $matches[1];
+
 		if ( ! $chmod )
 			$chmod = FS_CHMOD_DIR;

Not sure if your better off using strpos() or a better regex but the one above seems to fix all the issues I was having. I'm also not sure if it makes sense to apply a similar patch to the other filesystem mkdir() functions, although it's not likely necessary, it probably wouldn't hurt.

Cheers.

Change History (2)

#1 @jfine
15 years ago

Appears to relate to a PHP bug where mkdir fails with a trailing slash under safe_mode. The bug continues to go unresolved since 2002 so it still likely makes sense to update the WP code.

http://bugs.php.net/bug.php?id=16638
http://bugs.php.net/bug.php?id=42739
http://bugs.php.net/bug.php?id=43276

#2 @dd32
15 years ago

  • Milestone Unassigned deleted
  • Resolution set to duplicate
  • Status changed from new to closed

See:

[12741]: Fix WP_Filesystem_Direct::mkdir() when running under safe_mode on certain ...
Fix WP_Filesystem_Direct::mkdir() when running under safe_mode on certain versions of PHP. Props remi. Fixes #10497
By dd32 — 01/17/10 02:58:09

[12740]: Fix wp_mkdir_p() when running under safe_mode on certain PHP versions. ...
Fix wp_mkdir_p() when running under safe_mode on certain PHP versions. Props Denis-de-Bernardy. Fixes #8830
By dd32 — 01/17/10 02:45:01

Note: See TracTickets for help on using tickets.