mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-02 13:41:24 +01:00
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:
parent
a8793e00c0
commit
a87c1e3ca9
@ -116,9 +116,6 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
|||||||
* @return bool Returns true on success or false on failure.
|
* @return bool Returns true on success or false on failure.
|
||||||
*/
|
*/
|
||||||
function chmod($file, $mode = false, $recursive = false) {
|
function chmod($file, $mode = false, $recursive = false) {
|
||||||
if ( ! $this->exists($file) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ( ! $mode ) {
|
if ( ! $mode ) {
|
||||||
if ( $this->is_file($file) )
|
if ( $this->is_file($file) )
|
||||||
$mode = FS_CHMOD_FILE;
|
$mode = FS_CHMOD_FILE;
|
||||||
@ -128,9 +125,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $recursive )
|
if ( ! $recursive || ! $this->is_dir($file) )
|
||||||
return @chmod($file, $mode);
|
|
||||||
if ( ! $this->is_dir($file) )
|
|
||||||
return @chmod($file, $mode);
|
return @chmod($file, $mode);
|
||||||
//Is a directory, and we want recursive
|
//Is a directory, and we want recursive
|
||||||
$file = trailingslashit($file);
|
$file = trailingslashit($file);
|
||||||
@ -298,17 +293,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function rmdir($path, $recursive = false) {
|
function rmdir($path, $recursive = false) {
|
||||||
//Currently unused and untested, Use delete() instead.
|
return $this->delete($path, $recursive);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function dirlist($path, $include_hidden = true, $recursive = false) {
|
function dirlist($path, $include_hidden = true, $recursive = false) {
|
||||||
|
@ -142,9 +142,6 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
function chmod($file, $mode = false, $recursive = false) {
|
function chmod($file, $mode = false, $recursive = false) {
|
||||||
if ( ! $this->exists($file) && ! $this->is_dir($file) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ( ! $mode ) {
|
if ( ! $mode ) {
|
||||||
if ( $this->is_file($file) )
|
if ( $this->is_file($file) )
|
||||||
$mode = FS_CHMOD_FILE;
|
$mode = FS_CHMOD_FILE;
|
||||||
@ -245,11 +242,9 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
|
function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
|
||||||
if ( !ftp_mkdir($this->link, $path) )
|
if ( !ftp_mkdir($this->link, $path) )
|
||||||
return false;
|
return false;
|
||||||
if ( ! $chmod )
|
$this->chmod($path);
|
||||||
$chmod = FS_CHMOD_DIR;
|
|
||||||
$this->chmod($path, $chmod);
|
|
||||||
if ( $chown )
|
if ( $chown )
|
||||||
$this->chown($path, $chown);
|
$this->chown($path, $chown);
|
||||||
if ( $chgrp )
|
if ( $chgrp )
|
||||||
@ -263,12 +258,15 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||||||
function parselisting($line) {
|
function parselisting($line) {
|
||||||
static $is_windows;
|
static $is_windows;
|
||||||
if ( is_null($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();
|
$b = array();
|
||||||
if ( $lucifer[3] < 70 ) { $lucifer[3] +=2000; } else { $lucifer[3] += 1900; } // 4digit year fix
|
if ( $lucifer[3] < 70 )
|
||||||
$b['isdir'] = ($lucifer[7]=="<DIR>");
|
$lucifer[3] +=2000;
|
||||||
|
else
|
||||||
|
$lucifer[3] += 1900; // 4digit year fix
|
||||||
|
$b['isdir'] = ( $lucifer[7] == '<DIR>');
|
||||||
if ( $b['isdir'] )
|
if ( $b['isdir'] )
|
||||||
$b['type'] = 'd';
|
$b['type'] = 'd';
|
||||||
else
|
else
|
||||||
@ -279,13 +277,14 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||||||
$b['year'] = $lucifer[3];
|
$b['year'] = $lucifer[3];
|
||||||
$b['hour'] = $lucifer[4];
|
$b['hour'] = $lucifer[4];
|
||||||
$b['minute'] = $lucifer[5];
|
$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['am/pm'] = $lucifer[6];
|
||||||
$b['name'] = $lucifer[8];
|
$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";
|
//echo $line."\n";
|
||||||
$lcount=count($lucifer);
|
$lcount = count($lucifer);
|
||||||
if ($lcount<8) return '';
|
if ( $lcount < 8 )
|
||||||
|
return '';
|
||||||
$b = array();
|
$b = array();
|
||||||
$b['isdir'] = $lucifer[0]{0} === "d";
|
$b['isdir'] = $lucifer[0]{0} === "d";
|
||||||
$b['islink'] = $lucifer[0]{0} === "l";
|
$b['islink'] = $lucifer[0]{0} === "l";
|
||||||
@ -300,15 +299,15 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||||||
$b['owner'] = $lucifer[2];
|
$b['owner'] = $lucifer[2];
|
||||||
$b['group'] = $lucifer[3];
|
$b['group'] = $lucifer[3];
|
||||||
$b['size'] = $lucifer[4];
|
$b['size'] = $lucifer[4];
|
||||||
if ($lcount==8) {
|
if ( $lcount == 8 ) {
|
||||||
sscanf($lucifer[5],"%d-%d-%d",$b['year'],$b['month'],$b['day']);
|
sscanf($lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day']);
|
||||||
sscanf($lucifer[6],"%d:%d",$b['hour'],$b['minute']);
|
sscanf($lucifer[6], '%d:%d', $b['hour'], $b['minute']);
|
||||||
$b['time'] = @mktime($b['hour'],$b['minute'],0,$b['month'],$b['day'],$b['year']);
|
$b['time'] = @mktime($b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year']);
|
||||||
$b['name'] = $lucifer[7];
|
$b['name'] = $lucifer[7];
|
||||||
} else {
|
} else {
|
||||||
$b['month'] = $lucifer[5];
|
$b['month'] = $lucifer[5];
|
||||||
$b['day'] = $lucifer[6];
|
$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['year'] = date("Y");
|
||||||
$b['hour'] = $l2[1];
|
$b['hour'] = $l2[1];
|
||||||
$b['minute'] = $l2[2];
|
$b['minute'] = $l2[2];
|
||||||
@ -317,7 +316,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
|||||||
$b['hour'] = 0;
|
$b['hour'] = 0;
|
||||||
$b['minute'] = 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];
|
$b['name'] = $lucifer[8];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,6 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function chmod($file, $mode = false, $recursive = false ) {
|
function chmod($file, $mode = false, $recursive = false ) {
|
||||||
|
|
||||||
if ( ! $mode ) {
|
if ( ! $mode ) {
|
||||||
if ( $this->is_file($file) )
|
if ( $this->is_file($file) )
|
||||||
$mode = FS_CHMOD_FILE;
|
$mode = FS_CHMOD_FILE;
|
||||||
@ -277,10 +276,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function rmdir($path, $recursive = false ) {
|
function rmdir($path, $recursive = false ) {
|
||||||
if ( ! $recursive )
|
$this->delete($path, $recursive);
|
||||||
return $this->ftp->rmdir($path);
|
|
||||||
|
|
||||||
return $this->ftp->mdel($path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function dirlist($path = '.', $include_hidden = true, $recursive = false ) {
|
function dirlist($path = '.', $include_hidden = true, $recursive = false ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user