From 707676f0acbb0c7544ce767d96fa9644b538ceb2 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 15 Sep 2009 02:21:00 +0000 Subject: [PATCH] Include 'hidden' directories in filesystem dirlist by default, props dd32, fixes #10774 git-svn-id: https://develop.svn.wordpress.org/trunk@11934 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-filesystem-direct.php | 21 +++++---- .../includes/class-wp-filesystem-ftpext.php | 39 +++++++--------- .../class-wp-filesystem-ftpsockets.php | 44 +++++++++---------- .../includes/class-wp-filesystem-ssh2.php | 17 ++++--- 4 files changed, 63 insertions(+), 58 deletions(-) diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php index ed3f4f5b47..88e4a902a5 100644 --- a/wp-admin/includes/class-wp-filesystem-direct.php +++ b/wp-admin/includes/class-wp-filesystem-direct.php @@ -307,29 +307,34 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return @rmdir($path); } - function dirlist($path, $incdot = false, $recursive = false) { + function dirlist($path, $include_hidden = true, $recursive = false) { if ( $this->is_file($path) ) { - $limitFile = basename($path); + $limit_file = basename($path); $path = dirname($path); } else { - $limitFile = false; + $limit_file = false; } + if ( ! $this->is_dir($path) ) return false; - $ret = array(); $dir = @dir($path); if ( ! $dir ) return false; + + $ret = array(); + while (false !== ($entry = $dir->read()) ) { $struc = array(); $struc['name'] = $entry; if ( '.' == $struc['name'] || '..' == $struc['name'] ) - continue; //Do not care about these folders. - if ( '.' == $struc['name'][0] && !$incdot) continue; - if ( $limitFile && $struc['name'] != $limitFile) + + if ( ! $include_hidden && '.' == $struc['name'][0] ) + continue; + + if ( $limit_file && $struc['name'] != $limit_file) continue; $struc['perms'] = $this->gethchmod($path.'/'.$entry); @@ -345,7 +350,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { if ( 'd' == $struc['type'] ) { if ( $recursive ) - $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); + $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); else $struc['files'] = array(); } diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index 03609ff613..eff98b5e6d 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -323,12 +323,12 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { return $b; } - function dirlist($path = '.', $incdot = false, $recursive = false) { + function dirlist($path = '.', $include_hidden = true, $recursive = false) { if ( $this->is_file($path) ) { - $limitFile = basename($path); + $limit_file = basename($path); $path = dirname($path) . '/'; } else { - $limitFile = false; + $limit_file = false; } $list = @ftp_rawlist($this->link, '-a ' . $path, false); @@ -342,7 +342,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { if ( empty($entry) ) continue; - if ( '.' == $entry["name"] || '..' == $entry["name"] ) + if ( '.' == $entry['name'] || '..' == $entry['name'] ) + continue; + + if ( ! $include_hidden && '.' == $entry['name'][0] ) + continue; + + if ( $limit_file && $entry['name'] != $limit_file) continue; $dirlist[ $entry['name'] ] = $entry; @@ -350,28 +356,17 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { if ( ! $dirlist ) return false; - if ( empty($dirlist) ) - return array(); $ret = array(); - foreach ( $dirlist as $struc ) { - + foreach ( (array)$dirlist as $struc ) { if ( 'd' == $struc['type'] ) { - $struc['files'] = array(); - - if ( $incdot ) { - //We're including the doted starts - if ( '.' != $struc['name'] && '..' != $struc['name'] ) { //Ok, It isnt a special folder - if ($recursive) - $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); - } - } else { //No dots - if ($recursive) - $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); - } + if ( $recursive ) + $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); + else + $struc['files'] = array(); } - //File - $ret[$struc['name']] = $struc; + + $ret[ $struc['name'] ] = $struc; } return $ret; } diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index fd74c07176..3afa45e291 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -122,7 +122,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { $this->ftp->SetType($type); $temp = wp_tempnam( $file ); - if ( ! $temphandle = fopen($temp, 'w+') ){ + if ( ! $temphandle = fopen($temp, 'w+') ) { unlink($temp); return false; } @@ -166,11 +166,12 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { if ( ! $recursive || ! $this->is_dir($file) ) { return $this->ftp->chmod($file, $mode); } + //Is a directory, and we want recursive $filelist = $this->dirlist($file); - foreach($filelist as $filename){ + foreach ( $filelist as $filename ) $this->chmod($file . '/' . $filename, $mode, $recursive); - } + return true; } @@ -282,39 +283,38 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { return $this->ftp->mdel($path); } - function dirlist($path = '.', $incdot = false, $recursive = false ) { + function dirlist($path = '.', $include_hidden = true, $recursive = false ) { if ( $this->is_file($path) ) { - $limitFile = basename($path); + $limit_file = basename($path); $path = dirname($path) . '/'; } else { - $limitFile = false; + $limit_file = false; } $list = $this->ftp->dirlist($path); if ( ! $list ) return false; - if ( empty($list) ) - return array(); $ret = array(); foreach ( $list as $struc ) { - if ( 'd' == $struc['type'] ) { - $struc['files'] = array(); + if ( '.' == $struct['name'] || '..' == $struc['name'] ) + continue; - if ( $incdot ){ - //We're including the doted starts - if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder - if ($recursive) - $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); - } - } else { //No dots - if ($recursive) - $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); - } + if ( ! $include_hidden && '.' == $struc['name'][0] ) + continue; + + if ( $limit_file && $srtuc['name'] != $limit_file ) + continue; + + if ( 'd' == $struc['type'] ) { + if ( $recursive ) + $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); + else + $struc['files'] = array(); } - //File - $ret[$struc['name']] = $struc; + + $ret[ $struc['name'] ] = $struc; } return $ret; } diff --git a/wp-admin/includes/class-wp-filesystem-ssh2.php b/wp-admin/includes/class-wp-filesystem-ssh2.php index 78845918dd..0337658c9d 100644 --- a/wp-admin/includes/class-wp-filesystem-ssh2.php +++ b/wp-admin/includes/class-wp-filesystem-ssh2.php @@ -322,29 +322,34 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { return $this->delete($path, $recursive); } - function dirlist($path, $incdot = false, $recursive = false) { + function dirlist($path, $include_hidden = true, $recursive = false) { if ( $this->is_file($path) ) { - $limitFile = basename($path); + $limit_file = basename($path); $path = dirname($path); } else { - $limitFile = false; + $limit_file = false; } + if ( ! $this->is_dir($path) ) return false; $ret = array(); $dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') ); + if ( ! $dir ) return false; + while (false !== ($entry = $dir->read()) ) { $struc = array(); $struc['name'] = $entry; if ( '.' == $struc['name'] || '..' == $struc['name'] ) continue; //Do not care about these folders. - if ( '.' == $struc['name'][0] && !$incdot) + + if ( ! $include_hidden && '.' == $struc['name'][0] ) continue; - if ( $limitFile && $struc['name'] != $limitFile) + + if ( $limit_file && $struc['name'] != $limit_file ) continue; $struc['perms'] = $this->gethchmod($path.'/'.$entry); @@ -360,7 +365,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { if ( 'd' == $struc['type'] ) { if ( $recursive ) - $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); + $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); else $struc['files'] = array(); }