Include 'hidden' directories in filesystem dirlist by default, props dd32, fixes #10774

git-svn-id: http://svn.automattic.com/wordpress/trunk@11934 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-09-15 02:21:00 +00:00
parent 55c0ecb52f
commit 103ba096a7
4 changed files with 63 additions and 58 deletions

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();
}