WP_Filesystem: Let the code breathe, add some additional whitespace between method definitions and comments.

Built from https://develop.svn.wordpress.org/trunk@25305


git-svn-id: http://core.svn.wordpress.org/trunk@25267 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-09-09 02:55:09 +00:00
parent 6d1ffc62ea
commit 7a6fad844a
4 changed files with 68 additions and 31 deletions

View File

@ -20,6 +20,7 @@ class WP_Filesystem_Base {
* @var bool * @var bool
*/ */
var $verbose = false; var $verbose = false;
/** /**
* Cached list of local filepaths to mapped remote filepaths. * Cached list of local filepaths to mapped remote filepaths.
* *
@ -52,6 +53,7 @@ class WP_Filesystem_Base {
$folder = '/'; $folder = '/';
return $folder; return $folder;
} }
/** /**
* Returns the path on the remote filesystem of WP_CONTENT_DIR * Returns the path on the remote filesystem of WP_CONTENT_DIR
* *
@ -62,6 +64,7 @@ class WP_Filesystem_Base {
function wp_content_dir() { function wp_content_dir() {
return $this->find_folder(WP_CONTENT_DIR); return $this->find_folder(WP_CONTENT_DIR);
} }
/** /**
* Returns the path on the remote filesystem of WP_PLUGIN_DIR * Returns the path on the remote filesystem of WP_PLUGIN_DIR
* *
@ -73,6 +76,7 @@ class WP_Filesystem_Base {
function wp_plugins_dir() { function wp_plugins_dir() {
return $this->find_folder(WP_PLUGIN_DIR); return $this->find_folder(WP_PLUGIN_DIR);
} }
/** /**
* Returns the path on the remote filesystem of the Themes Directory * Returns the path on the remote filesystem of the Themes Directory
* *
@ -91,6 +95,7 @@ class WP_Filesystem_Base {
return $this->find_folder( $theme_root ); return $this->find_folder( $theme_root );
} }
/** /**
* Returns the path on the remote filesystem of WP_LANG_DIR * Returns the path on the remote filesystem of WP_LANG_DIR
* *
@ -121,6 +126,7 @@ class WP_Filesystem_Base {
$this->verbose = $echo; $this->verbose = $echo;
return $this->abspath(); return $this->abspath();
} }
/** /**
* Locates a folder on the remote filesystem. * Locates a folder on the remote filesystem.
* *

View File

@ -25,6 +25,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
$this->method = 'direct'; $this->method = 'direct';
$this->errors = new WP_Error(); $this->errors = new WP_Error();
} }
/** /**
* connect filesystem. * connect filesystem.
* *
@ -33,6 +34,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
function connect() { function connect() {
return true; return true;
} }
/** /**
* Reads entire file into a string * Reads entire file into a string
* *
@ -42,6 +44,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
function get_contents($file) { function get_contents($file) {
return @file_get_contents($file); return @file_get_contents($file);
} }
/** /**
* Reads entire file into an array * Reads entire file into an array
* *
@ -51,6 +54,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
function get_contents_array($file) { function get_contents_array($file) {
return @file($file); return @file($file);
} }
/** /**
* Write a string to a file * Write a string to a file
* *
@ -75,6 +79,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return true; return true;
} }
/** /**
* Gets the current working directory * Gets the current working directory
* *
@ -83,6 +88,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
function cwd() { function cwd() {
return @getcwd(); return @getcwd();
} }
/** /**
* Change directory * Change directory
* *
@ -92,6 +98,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
function chdir($dir) { function chdir($dir) {
return @chdir($dir); return @chdir($dir);
} }
/** /**
* Changes file group * Changes file group
* *
@ -115,6 +122,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return true; return true;
} }
/** /**
* Changes filesystem permissions * Changes filesystem permissions
* *
@ -143,6 +151,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return true; return true;
} }
/** /**
* Changes file owner * Changes file owner
* *
@ -165,6 +174,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
} }
return true; return true;
} }
/** /**
* Gets file owner * Gets file owner
* *
@ -180,6 +190,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
$ownerarray = posix_getpwuid($owneruid); $ownerarray = posix_getpwuid($owneruid);
return $ownerarray['name']; return $ownerarray['name'];
} }
/** /**
* Gets file permissions * Gets file permissions
* *
@ -191,6 +202,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
function getchmod($file) { function getchmod($file) {
return substr(decoct(@fileperms($file)),3); return substr(decoct(@fileperms($file)),3);
} }
function group($file) { function group($file) {
$gid = @filegroup($file); $gid = @filegroup($file);
if ( ! $gid ) if ( ! $gid )
@ -242,13 +254,16 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
$filelist = $this->dirlist($file, true); $filelist = $this->dirlist($file, true);
$retval = true; $retval = true;
if ( is_array($filelist) ) //false if no files, So check first. if ( is_array( $filelist ) ) {
foreach ($filelist as $filename => $fileinfo) foreach ( $filelist as $filename => $fileinfo ) {
if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) ) if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) )
$retval = false; $retval = false;
}
}
if ( file_exists($file) && ! @rmdir($file) ) if ( file_exists($file) && ! @rmdir($file) )
$retval = false; $retval = false;
return $retval; return $retval;
} }
@ -279,6 +294,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
function mtime($file) { function mtime($file) {
return @filemtime($file); return @filemtime($file);
} }
function size($file) { function size($file) {
return @filesize($file); return @filesize($file);
} }

View File

@ -29,7 +29,6 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return false; return false;
} }
// Set defaults:
// This Class uses the timeout on a per-connection basis, Others use it on a per-action basis. // This Class uses the timeout on a per-connection basis, Others use it on a per-action basis.
if ( ! defined('FS_TIMEOUT') ) if ( ! defined('FS_TIMEOUT') )
@ -108,6 +107,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
unlink($tempfile); unlink($tempfile);
return $contents; return $contents;
} }
function get_contents_array($file) { function get_contents_array($file) {
return explode("\n", $this->get_contents($file)); return explode("\n", $this->get_contents($file));
} }
@ -136,18 +136,22 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return $ret; return $ret;
} }
function cwd() { function cwd() {
$cwd = @ftp_pwd($this->link); $cwd = @ftp_pwd($this->link);
if ( $cwd ) if ( $cwd )
$cwd = trailingslashit($cwd); $cwd = trailingslashit($cwd);
return $cwd; return $cwd;
} }
function chdir($dir) { function chdir($dir) {
return @ftp_chdir($this->link, $dir); return @ftp_chdir($this->link, $dir);
} }
function chgrp($file, $group, $recursive = false ) { function chgrp($file, $group, $recursive = false ) {
return false; return false;
} }
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) )
@ -170,21 +174,26 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return (bool)@ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file)); return (bool)@ftp_site($this->link, sprintf('CHMOD %o %s', $mode, $file));
return (bool)@ftp_chmod($this->link, $mode, $file); return (bool)@ftp_chmod($this->link, $mode, $file);
} }
function chown($file, $owner, $recursive = false ) { function chown($file, $owner, $recursive = false ) {
return false; return false;
} }
function owner($file) { function owner($file) {
$dir = $this->dirlist($file); $dir = $this->dirlist($file);
return $dir[$file]['owner']; return $dir[$file]['owner'];
} }
function getchmod($file) { function getchmod($file) {
$dir = $this->dirlist($file); $dir = $this->dirlist($file);
return $dir[$file]['permsn']; return $dir[$file]['permsn'];
} }
function group($file) { function group($file) {
$dir = $this->dirlist($file); $dir = $this->dirlist($file);
return $dir[$file]['group']; return $dir[$file]['group'];
} }
function copy($source, $destination, $overwrite = false, $mode = false) { function copy($source, $destination, $overwrite = false, $mode = false) {
if ( ! $overwrite && $this->exists($destination) ) if ( ! $overwrite && $this->exists($destination) )
return false; return false;
@ -193,6 +202,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
return false; return false;
return $this->put_contents($destination, $content, $mode); return $this->put_contents($destination, $content, $mode);
} }
function move($source, $destination, $overwrite = false) { function move($source, $destination, $overwrite = false) {
return ftp_rename($this->link, $source, $destination); return ftp_rename($this->link, $source, $destination);
} }
@ -216,9 +226,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$list = @ftp_nlist($this->link, $file); $list = @ftp_nlist($this->link, $file);
return !empty($list); //empty list = no file, so invert. return !empty($list); //empty list = no file, so invert.
} }
function is_file($file) { function is_file($file) {
return $this->exists($file) && !$this->is_dir($file); return $this->exists($file) && !$this->is_dir($file);
} }
function is_dir($path) { function is_dir($path) {
$cwd = $this->cwd(); $cwd = $this->cwd();
$result = @ftp_chdir($this->link, trailingslashit($path) ); $result = @ftp_chdir($this->link, trailingslashit($path) );
@ -228,26 +240,31 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
} }
return false; return false;
} }
function is_readable($file) { function is_readable($file) {
//Get dir list, Check if the file is readable by the current user??
return true; return true;
} }
function is_writable($file) { function is_writable($file) {
//Get dir list, Check if the file is writable by the current user??
return true; return true;
} }
function atime($file) { function atime($file) {
return false; return false;
} }
function mtime($file) { function mtime($file) {
return ftp_mdtm($this->link, $file); return ftp_mdtm($this->link, $file);
} }
function size($file) { function size($file) {
return ftp_size($this->link, $file); return ftp_size($this->link, $file);
} }
function touch($file, $time = 0, $atime = 0) { function touch($file, $time = 0, $atime = 0) {
return false; return false;
} }
function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
$path = untrailingslashit($path); $path = untrailingslashit($path);
if ( empty($path) ) if ( empty($path) )
@ -262,6 +279,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$this->chgrp($path, $chgrp); $this->chgrp($path, $chgrp);
return true; return true;
} }
function rmdir($path, $recursive = false) { function rmdir($path, $recursive = false) {
return $this->delete($path, $recursive); return $this->delete($path, $recursive);
} }

View File

@ -28,7 +28,6 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return false; return false;
$this->ftp = new ftp(); $this->ftp = new ftp();
//Set defaults:
if ( empty($opt['port']) ) if ( empty($opt['port']) )
$this->options['port'] = 21; $this->options['port'] = 21;
else else
@ -242,12 +241,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
} }
function is_readable($file) { function is_readable($file) {
//Get dir list, Check if the file is writable by the current user??
return true; return true;
} }
function is_writable($file) { function is_writable($file) {
//Get dir list, Check if the file is writable by the current user??
return true; return true;
} }