WPFS cleanups. Props DD32. fixes #9525

git-svn-id: http://svn.automattic.com/wordpress/trunk@10919 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-04-13 16:11:02 +00:00
parent 3dd79f8587
commit 31a2bbad76
4 changed files with 84 additions and 68 deletions

View File

@ -46,8 +46,6 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
function abspath() {
if ( defined('FTP_BASE') && strpos($this->method, 'ftp') !== false )
return FTP_BASE;
$folder = $this->find_folder(ABSPATH);
//Perhaps the FTP folder is rooted at the WordPress install, Check for wp-includes folder in root, Could have some false positives, but rare.
if ( ! $folder && $this->is_dir('/wp-includes') )
@ -62,8 +60,6 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
function wp_content_dir() {
if ( defined('FTP_CONTENT_DIR') && strpos($this->method, 'ftp') !== false )
return FTP_CONTENT_DIR;
return $this->find_folder(WP_CONTENT_DIR);
}
/**
@ -75,8 +71,6 @@ class WP_Filesystem_Base {
* @return string The location of the remote path.
*/
function wp_plugins_dir() {
if ( defined('FTP_PLUGIN_DIR') && strpos($this->method, 'ftp') !== false )
return FTP_PLUGIN_DIR;
return $this->find_folder(WP_PLUGIN_DIR);
}
/**
@ -142,6 +136,15 @@ class WP_Filesystem_Base {
*/
function find_folder($folder) {
if ( strpos($this->method, 'ftp') !== false ) {
$constant_overrides = array( 'FTP_BASE' => ABSPATH, 'FTP_CONTENT_DIR' => WP_CONTENT_DIR, 'FTP_PLUGIN_DIR' => WP_PLUGIN_DIR );
foreach ( $constant_overrides as $constant => $dir )
if ( defined($constant) && $folder === $dir )
return trailingslashit(constant($constant));
} elseif ( 'direct' == $this->method ) {
return trailingslashit($folder);
}
$folder = preg_replace('|^([a-z]{1}):|i', '', $folder); //Strip out windows driveletter if its there.
$folder = str_replace('\\', '/', $folder); //Windows path sanitiation
@ -149,6 +152,7 @@ class WP_Filesystem_Base {
return $this->cache[ $folder ];
if ( $this->exists($folder) ) { //Folder exists at that absolute path.
$folder = trailingslashit($folder);
$this->cache[ $folder ] = $folder;
return $folder;
}
@ -203,7 +207,7 @@ class WP_Filesystem_Base {
if (isset( $files[ $last_path ] ) ) {
if ( $this->verbose )
printf( __('Found %s') . '<br/>', $base . $last_path );
return $base . $last_path;
return trailingslashit($base . $last_path);
}
if ( $loop )
return false;//Prevent tihs function looping again.

View File

@ -16,7 +16,7 @@
*/
class WP_Filesystem_Direct extends WP_Filesystem_Base {
var $permission = null;
var $errors = array();
var $errors = null;
function WP_Filesystem_Direct($arg) {
$this->method = 'direct';
$this->errors = new WP_Error();
@ -104,7 +104,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return $ownerarray['name'];
}
function getchmod($file) {
return @fileperms($file);
return substr(decoct(@fileperms($file)),3);
}
function group($file) {
$gid = @filegroup($file);
@ -133,6 +133,8 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
}
function delete($file, $recursive = false) {
if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
return false;
$file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise
if ( $this->is_file($file) )
@ -150,8 +152,8 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( ! $this->delete($file . $filename, $recursive) )
$retval = false;
if( ! @rmdir($file) )
return false;
if ( file_exists($file) && ! @rmdir($file) )
$retval = false;
return $retval;
}

View File

@ -169,7 +169,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
}
function getchmod($file) {
$dir = $this->dirlist($file);
return $dir[$file]['permsn'];
return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
}
function group($file) {
$dir = $this->dirlist($file);
@ -188,6 +188,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
}
function delete($file ,$recursive = false ) {
if ( empty($file) )
return false;
if ( $this->is_file($file) )
return @ftp_delete($this->link, $file);
if ( !$recursive )
@ -321,11 +323,12 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
}
function dirlist($path = '.', $incdot = false, $recursive = false) {
if( $this->is_file($path) ) {
$limitFile = basename($path);
$path = dirname($path) . '/';
if ( substr($path, -1) !== '/') {
$limit = basename($path);
$path = trailingslashit(dirname($path));
} else {
$limitFile = false;
$limit = false;
}
$list = @ftp_rawlist($this->link, '-a ' . $path, false);
@ -339,7 +342,10 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( empty($entry) )
continue;
if ( '.' == $entry["name"] || '..' == $entry["name"] )
if ( '.' == $entry['name'] || '..' == $entry['name'] )
continue;
if ( $limit && $entry['name'] != $limit )
continue;
$dirlist[ $entry['name'] ] = $entry;

View File

@ -186,7 +186,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
function getchmod($file) {
$dir = $this->dirlist($file);
return $dir[$file]['permsn'];
return $this->getnumchmodfromh( $dir[basename($file)]['perms'] );
}
function group($file) {
@ -281,21 +281,25 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
}
function dirlist($path = '.', $incdot = false, $recursive = false ) {
if( $this->is_file($path) ) {
$limitFile = basename($path);
$path = dirname($path) . '/';
if ( substr($path, -1) !== '/') {
$limit = basename($path);
$path = trailingslashit(dirname($path));
} else {
$limitFile = false;
$limit = false;
}
$list = $this->ftp->dirlist($path);
if( ! $list )
return false;
if( empty($list) )
return array();
$ret = array();
foreach ( $list as $struc ) {
if ( $limit && $struc['name'] != $limit )
continue;
if ( 'd' == $struc['type'] ) {
$struc['files'] = array();