Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#11261 closed defect (bug) (fixed)

method chmod in WP_Filesystem doesn't work in recursive mode

Reported by: ghue's profile G.Hue Owned by: dd32's profile dd32
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.8.4
Component: Filesystem API Keywords: has-patch
Focuses: Cc:


The following code doesn't work when recursive mode is used :
File wp-admin\includes\class-wp-filesystem-ftpext.php
Line 142

function chmod($file, $mode = false, $recursive = false) {
		if( ! $mode )
			$mode = $this->permission;
		if( ! $mode )
			return false;
		if ( ! $this->exists($file) && ! $this->is_dir($file) )
			return false;
		if ( ! $recursive || ! $this->is_dir($file) ) {
			if ( ! function_exists('ftp_chmod') ){
				return @ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
			echo "@ftp_chmod(_$this->link, $mode, $file);";
			return @ftp_chmod($this->link, $mode, $file);
		//Is a directory, and we want recursive
		$filelist = $this->dirlist($file);
		foreach($filelist as $filename){
			$this->chmod($file . '/' . $filename, $mode, $recursive);
		return true;

No chmod is apply on the directory. Chmod is apply only on subfiles (and subdirectories but the same problem appear...)

$this->dirlist return an array of array. On this case:

$this->chmod($file . '/' . $filename, $mode, $recursive);

$filename is an array, not the filename. It can't work.

Attachments (2)

recursive-chmod-ftpext-fix.txt (1.0 KB) - added by reaperhulk 14 years ago.
first attempt at fixing this bug
recursive-chmod.patch (1.3 KB) - added by reaperhulk 14 years ago.
Patch using svn diff.

Download all attachments as: .zip

Change History (10)

#1 @dd32
14 years ago

  • Component changed from General to Filesystem
  • Keywords needs-patch added; ftpext chmod class-wp-filesystem-ftpext.php removed
  • Milestone changed from Unassigned to 2.9
  • Owner set to dd32
  • Status changed from new to accepted

#2 @ryan
14 years ago

  • Milestone changed from 2.9 to 3.0

See also #10889

Postponing to 3.0 since we don't have a patch.

#3 @dd32
14 years ago

  • Summary changed from method chmod in class-wp-filesystem-ftpext doesn't work in recursive mode to method chmod in WP_Filesystem doesn't work in recursive mode

What should the settings on the directories be set to? ($mode & exec (browse) bits?)

14 years ago

first attempt at fixing this bug

#4 @reaperhulk
14 years ago

The attachment above is my attempt at fixing this bug. I reordered the logic so it checks to see if it's recursive and a directory first. It will then recursively call chmod (using the proper filename now).

#5 @reaperhulk
14 years ago

  • Cc reaperhulk added

#6 @reaperhulk
14 years ago

  • Keywords has-patch added; needs-patch removed

14 years ago

Patch using svn diff.

#7 @dd32
14 years ago

The only problem i can see with that is that in some cases, you'll need to chmod the folder before you can get a directory listing.. That should be a pretty rare case however.

I'm going to attempt testing this shortly along with a few other changes.

#8 @dd32
14 years ago

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

(In [12997]) Fix recursive chmod for WP_Filesystem. Props reaperhulk for FtpExt. Fixes #11261

Note: See TracTickets for help on using tickets.