Reduce code duplication, Formatting cleanups, Reduce Chmod IO calls. See #10913 for excess IO calls.

git-svn-id: http://svn.automattic.com/wordpress/trunk@12998 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-02-07 01:31:40 +00:00
parent a8793e00c0
commit a87c1e3ca9
3 changed files with 23 additions and 43 deletions

View File

@ -116,9 +116,6 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
* @return bool Returns true on success or false on failure.
*/
function chmod($file, $mode = false, $recursive = false) {
if ( ! $this->exists($file) )
return false;
if ( ! $mode ) {
if ( $this->is_file($file) )
$mode = FS_CHMOD_FILE;
@ -128,9 +125,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return false;
}
if ( ! $recursive )
return @chmod($file, $mode);
if ( ! $this->is_dir($file) )
if ( ! $recursive || ! $this->is_dir($file) )
return @chmod($file, $mode);
//Is a directory, and we want recursive
$file = trailingslashit($file);
@ -298,17 +293,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
}
function rmdir($path, $recursive = false) {
//Currently unused and untested, Use delete() instead.
if ( ! $recursive )
return @rmdir($path);
//recursive:
$filelist = $this->dirlist($path);
foreach ($filelist as $filename => $det) {
if ( '/' == substr($filename, -1, 1) )
$this->rmdir($path . '/' . $filename, $recursive);
@rmdir($filename);
}
return @rmdir($path);
return $this->delete($path, $recursive);
}
function dirlist($path, $include_hidden = true, $recursive = false) {

View File

@ -142,9 +142,6 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return false;
}
function chmod($file, $mode = false, $recursive = false) {
if ( ! $this->exists($file) && ! $this->is_dir($file) )
return false;
if ( ! $mode ) {
if ( $this->is_file($file) )
$mode = FS_CHMOD_FILE;
@ -245,11 +242,9 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return false;
}
function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
if ( !ftp_mkdir($this->link, $path) )
if ( !ftp_mkdir($this->link, $path) )
return false;
if ( ! $chmod )
$chmod = FS_CHMOD_DIR;
$this->chmod($path, $chmod);
$this->chmod($path);
if ( $chown )
$this->chown($path, $chown);
if ( $chgrp )
@ -263,12 +258,15 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
function parselisting($line) {
static $is_windows;
if ( is_null($is_windows) )
$is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false;
$is_windows = strpos( strtolower( ftp_systype($this->link) ), 'win') !== false;
if ( $is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer) ) {
if ( $is_windows && preg_match('/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer) ) {
$b = array();
if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix
$b['isdir'] = ($lucifer[7]=="<DIR>");
if ( $lucifer[3] < 70 )
$lucifer[3] +=2000;
else
$lucifer[3] += 1900; // 4digit year fix
$b['isdir'] = ( $lucifer[7] == '<DIR>');
if ( $b['isdir'] )
$b['type'] = 'd';
else
@ -279,13 +277,14 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$b['year'] = $lucifer[3];
$b['hour'] = $lucifer[4];
$b['minute'] = $lucifer[5];
$b['time'] = @mktime($lucifer[4]+(strcasecmp($lucifer[6],"PM")==0?12:0),$lucifer[5],0,$lucifer[1],$lucifer[2],$lucifer[3]);
$b['time'] = @mktime($lucifer[4] + (strcasecmp($lucifer[6], "PM") == 0 ? 12 : 0), $lucifer[5], 0, $lucifer[1], $lucifer[2], $lucifer[3]);
$b['am/pm'] = $lucifer[6];
$b['name'] = $lucifer[8];
} else if (!$is_windows && $lucifer=preg_split("/[ ]/",$line,9,PREG_SPLIT_NO_EMPTY)) {
} elseif ( !$is_windows && $lucifer = preg_split('/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY)) {
//echo $line."\n";
$lcount=count($lucifer);
if ($lcount<8) return '';
$lcount = count($lucifer);
if ( $lcount < 8 )
return '';
$b = array();
$b['isdir'] = $lucifer[0]{0} === "d";
$b['islink'] = $lucifer[0]{0} === "l";
@ -300,15 +299,15 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3];
$b['size'] = $lucifer[4];
if ($lcount==8) {
sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
$b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
if ( $lcount == 8 ) {
sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
$b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
$b['name'] = $lucifer[7];
} else {
$b['month'] = $lucifer[5];
$b['day'] = $lucifer[6];
if (preg_match("/([0-9]{2}):([0-9]{2})/",$lucifer[7],$l2)) {
if ( preg_match('/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2) ) {
$b['year'] = date("Y");
$b['hour'] = $l2[1];
$b['minute'] = $l2[2];
@ -317,7 +316,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$b['hour'] = 0;
$b['minute'] = 0;
}
$b['time'] = strtotime(sprintf("%d %s %d %02d:%02d",$b['day'],$b['month'],$b['year'],$b['hour'],$b['minute']));
$b['time'] = strtotime( sprintf('%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute']) );
$b['name'] = $lucifer[8];
}
}

View File

@ -154,7 +154,6 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
}
function chmod($file, $mode = false, $recursive = false ) {
if ( ! $mode ) {
if ( $this->is_file($file) )
$mode = FS_CHMOD_FILE;
@ -277,10 +276,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
}
function rmdir($path, $recursive = false ) {
if ( ! $recursive )
return $this->ftp->rmdir($path);
return $this->ftp->mdel($path);
$this->delete($path, $recursive);
}
function dirlist($path = '.', $include_hidden = true, $recursive = false ) {