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
This commit is contained in:
Andrew Ozz 2009-09-15 02:21:00 +00:00
parent fa9b9d3ad3
commit 707676f0ac
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); return @rmdir($path);
} }
function dirlist($path, $incdot = false, $recursive = false) { function dirlist($path, $include_hidden = true, $recursive = false) {
if ( $this->is_file($path) ) { if ( $this->is_file($path) ) {
$limitFile = basename($path); $limit_file = basename($path);
$path = dirname($path); $path = dirname($path);
} else { } else {
$limitFile = false; $limit_file = false;
} }
if ( ! $this->is_dir($path) ) if ( ! $this->is_dir($path) )
return false; return false;
$ret = array();
$dir = @dir($path); $dir = @dir($path);
if ( ! $dir ) if ( ! $dir )
return false; return false;
$ret = array();
while (false !== ($entry = $dir->read()) ) { while (false !== ($entry = $dir->read()) ) {
$struc = array(); $struc = array();
$struc['name'] = $entry; $struc['name'] = $entry;
if ( '.' == $struc['name'] || '..' == $struc['name'] ) if ( '.' == $struc['name'] || '..' == $struc['name'] )
continue; //Do not care about these folders.
if ( '.' == $struc['name'][0] && !$incdot)
continue; continue;
if ( $limitFile && $struc['name'] != $limitFile)
if ( ! $include_hidden && '.' == $struc['name'][0] )
continue;
if ( $limit_file && $struc['name'] != $limit_file)
continue; continue;
$struc['perms'] = $this->gethchmod($path.'/'.$entry); $struc['perms'] = $this->gethchmod($path.'/'.$entry);
@ -345,7 +350,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( 'd' == $struc['type'] ) { if ( 'd' == $struc['type'] ) {
if ( $recursive ) if ( $recursive )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
else else
$struc['files'] = array(); $struc['files'] = array();
} }

View File

@ -323,12 +323,12 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return $b; return $b;
} }
function dirlist($path = '.', $incdot = false, $recursive = false) { function dirlist($path = '.', $include_hidden = true, $recursive = false) {
if ( $this->is_file($path) ) { if ( $this->is_file($path) ) {
$limitFile = basename($path); $limit_file = basename($path);
$path = dirname($path) . '/'; $path = dirname($path) . '/';
} else { } else {
$limitFile = false; $limit_file = false;
} }
$list = @ftp_rawlist($this->link, '-a ' . $path, false); $list = @ftp_rawlist($this->link, '-a ' . $path, false);
@ -342,7 +342,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( empty($entry) ) if ( empty($entry) )
continue; 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; continue;
$dirlist[ $entry['name'] ] = $entry; $dirlist[ $entry['name'] ] = $entry;
@ -350,28 +356,17 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( ! $dirlist ) if ( ! $dirlist )
return false; return false;
if ( empty($dirlist) )
return array();
$ret = array(); $ret = array();
foreach ( $dirlist as $struc ) { foreach ( (array)$dirlist as $struc ) {
if ( 'd' == $struc['type'] ) { if ( 'd' == $struc['type'] ) {
$struc['files'] = array(); if ( $recursive )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
if ( $incdot ) { else
//We're including the doted starts $struc['files'] = array();
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);
}
} }
//File
$ret[$struc['name']] = $struc; $ret[ $struc['name'] ] = $struc;
} }
return $ret; return $ret;
} }

View File

@ -122,7 +122,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$this->ftp->SetType($type); $this->ftp->SetType($type);
$temp = wp_tempnam( $file ); $temp = wp_tempnam( $file );
if ( ! $temphandle = fopen($temp, 'w+') ){ if ( ! $temphandle = fopen($temp, 'w+') ) {
unlink($temp); unlink($temp);
return false; return false;
} }
@ -166,11 +166,12 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( ! $recursive || ! $this->is_dir($file) ) { if ( ! $recursive || ! $this->is_dir($file) ) {
return $this->ftp->chmod($file, $mode); return $this->ftp->chmod($file, $mode);
} }
//Is a directory, and we want recursive //Is a directory, and we want recursive
$filelist = $this->dirlist($file); $filelist = $this->dirlist($file);
foreach($filelist as $filename){ foreach ( $filelist as $filename )
$this->chmod($file . '/' . $filename, $mode, $recursive); $this->chmod($file . '/' . $filename, $mode, $recursive);
}
return true; return true;
} }
@ -282,39 +283,38 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return $this->ftp->mdel($path); 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) ) { if ( $this->is_file($path) ) {
$limitFile = basename($path); $limit_file = basename($path);
$path = dirname($path) . '/'; $path = dirname($path) . '/';
} else { } else {
$limitFile = false; $limit_file = false;
} }
$list = $this->ftp->dirlist($path); $list = $this->ftp->dirlist($path);
if ( ! $list ) if ( ! $list )
return false; return false;
if ( empty($list) )
return array();
$ret = array(); $ret = array();
foreach ( $list as $struc ) { foreach ( $list as $struc ) {
if ( 'd' == $struc['type'] ) { if ( '.' == $struct['name'] || '..' == $struc['name'] )
$struc['files'] = array(); continue;
if ( $incdot ){ if ( ! $include_hidden && '.' == $struc['name'][0] )
//We're including the doted starts continue;
if ( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
if ($recursive) if ( $limit_file && $srtuc['name'] != $limit_file )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); continue;
}
} else { //No dots if ( 'd' == $struc['type'] ) {
if ($recursive) 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();
} }
//File
$ret[$struc['name']] = $struc; $ret[ $struc['name'] ] = $struc;
} }
return $ret; return $ret;
} }

View File

@ -322,29 +322,34 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
return $this->delete($path, $recursive); 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) ) { if ( $this->is_file($path) ) {
$limitFile = basename($path); $limit_file = basename($path);
$path = dirname($path); $path = dirname($path);
} else { } else {
$limitFile = false; $limit_file = false;
} }
if ( ! $this->is_dir($path) ) if ( ! $this->is_dir($path) )
return false; return false;
$ret = array(); $ret = array();
$dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') ); $dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') );
if ( ! $dir ) if ( ! $dir )
return false; return false;
while (false !== ($entry = $dir->read()) ) { while (false !== ($entry = $dir->read()) ) {
$struc = array(); $struc = array();
$struc['name'] = $entry; $struc['name'] = $entry;
if ( '.' == $struc['name'] || '..' == $struc['name'] ) if ( '.' == $struc['name'] || '..' == $struc['name'] )
continue; //Do not care about these folders. continue; //Do not care about these folders.
if ( '.' == $struc['name'][0] && !$incdot)
if ( ! $include_hidden && '.' == $struc['name'][0] )
continue; continue;
if ( $limitFile && $struc['name'] != $limitFile)
if ( $limit_file && $struc['name'] != $limit_file )
continue; continue;
$struc['perms'] = $this->gethchmod($path.'/'.$entry); $struc['perms'] = $this->gethchmod($path.'/'.$entry);
@ -360,7 +365,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( 'd' == $struc['type'] ) { if ( 'd' == $struc['type'] ) {
if ( $recursive ) if ( $recursive )
$struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
else else
$struc['files'] = array(); $struc['files'] = array();
} }