WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#11261 closed defect (bug) (fixed)

method chmod in WP_Filesystem doesn't work in recursive mode

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

Description

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 6 years ago.
first attempt at fixing this bug
recursive-chmod.patch (1.3 KB) - added by reaperhulk 6 years ago.
Patch using svn diff.

Download all attachments as: .zip

Change History (10)

comment:1 @dd326 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

comment:2 @ryan6 years ago

  • Milestone changed from 2.9 to 3.0

See also #10889

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

comment:3 @dd326 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?)

@reaperhulk6 years ago

first attempt at fixing this bug

comment:4 @reaperhulk6 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).

comment:5 @reaperhulk6 years ago

  • Cc reaperhulk added

comment:6 @reaperhulk6 years ago

  • Keywords has-patch added; needs-patch removed

@reaperhulk6 years ago

Patch using svn diff.

comment:7 @dd326 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.

comment:8 @dd326 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.