wp-fs fixes from DD32. see #5586

git-svn-id: https://develop.svn.wordpress.org/trunk@7155 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-03-04 17:10:17 +00:00
parent 9266ee91aa
commit dc6c68d79a
4 changed files with 24 additions and 19 deletions

View File

@ -13,11 +13,11 @@ class WP_Filesystem_Direct{
function setDefaultPermissions($perm){
$this->permission = $perm;
}
function find_base_dir($base = '.'){
function find_base_dir($base = '.', $echo = false){
return str_replace('\\','/',ABSPATH);
}
function get_base_dir($base = '.'){
return str_replace('\\','/',ABSPATH);
function get_base_dir($base = '.', $echo = false){
return find_base_dir($base, $echo);
}
function get_contents($file){
return @file_get_contents($file);

View File

@ -62,9 +62,9 @@ class WP_Filesystem_FTPext{
function connect(){
if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) {
$this->link = ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout);
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout);
} else {
$this->link = ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout);
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout);
}
if ( ! $this->link ) {
@ -72,7 +72,7 @@ class WP_Filesystem_FTPext{
return false;
}
if ( ! ftp_login($this->link,$this->options['username'], $this->options['password']) ) {
if ( ! @ftp_login($this->link,$this->options['username'], $this->options['password']) ) {
$this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
return false;
}
@ -119,9 +119,9 @@ class WP_Filesystem_FTPext{
//If we get this far, somethings gone wrong, change to / and restart the process.
return $this->find_base_dir('/',$echo);
}
function get_base_dir($base = '.'){
function get_base_dir($base = '.', $echo=false){
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($base);
$this->wp_base = $this->find_base_dir($base,$echo);
return $this->wp_base;
}
function get_contents($file,$type='',$resumepos=0){
@ -298,7 +298,8 @@ class WP_Filesystem_FTPext{
}
function is_dir($path){
$cwd = $this->cwd();
if ( @ftp_chdir($this->link, $path) ) {
@ftp_chdir($this->link, $path);
if ( $this->cwd() != $cwd ) {
@ftp_chdir($this->link, $cwd);
return true;
}
@ -325,7 +326,7 @@ class WP_Filesystem_FTPext{
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 )
$this->chmod($path, $chmod);
@ -337,7 +338,7 @@ class WP_Filesystem_FTPext{
}
function rmdir($path,$recursive=false){
if( ! $recursive )
return ftp_rmdir($this->link, $file);
return @ftp_rmdir($this->link, $file);
//TODO: Recursive Directory delete, Have to delete files from the folder first.
//$dir = $this->dirlist($path);

View File

@ -122,9 +122,9 @@ class WP_Filesystem_ftpsockets{
return $this->find_base_dir('/',$echo);
}
function get_base_dir($base = '.'){
function get_base_dir($base = '.', $echo = false){
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($base);
$this->wp_base = $this->find_base_dir($base, $echo);
return $this->wp_base;
}

View File

@ -140,6 +140,9 @@ function wp_update_plugin($plugin, $feedback = '') {
if ( $wp_filesystem->errors->get_error_code() )
return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
//Get the Base folder
$base = $wp_filesystem->get_base_dir();
// Get the URL to the zip file
$r = $current->response[ $plugin ];
@ -148,14 +151,14 @@ function wp_update_plugin($plugin, $feedback = '') {
// Download the package
$package = $r->package;
apply_filters('update_feedback', __("Downloading update from $package"));
apply_filters('update_feedback', sprintf(__("Downloading update from %s"), $package));
$file = download_url($package);
if ( !$file )
return new WP_Error('download_failed', __('Download failed.'));
$name = basename($plugin, '.php');
$working_dir = ABSPATH . 'wp-content/upgrade/' . $name;
$working_dir = $base . 'wp-content/upgrade/' . $name;
// Clean up working directory
if ( is_dir($working_dir) )
@ -175,12 +178,13 @@ function wp_update_plugin($plugin, $feedback = '') {
// Remove the existing plugin.
apply_filters('update_feedback', __("Removing the old version of the plugin"));
$plugin_dir = dirname(ABSPATH . PLUGINDIR . "/$plugin");
$plugin_dir = dirname($base . PLUGINDIR . "/$plugin");
$plugin_dir = trailingslashit($plugin_dir);
// If plugin is in its own directory, recursively delete the directory.
if ( '.' != $plugin_dir && ABSPATH . PLUGINDIR != $plugin_dir )
if ( '.' != $plugin_dir && $base . PLUGINDIR != $plugin_dir )
$deleted = $wp_filesystem->delete($plugin_dir, true);
else
$deleted = $wp_filesystem->delete(ABSPATH . PLUGINDIR . "/$plugin");
$deleted = $wp_filesystem->delete($base . PLUGINDIR . "/$plugin");
if ( !$deleted ) {
$wp_filesystem->delete($working_dir, true);
return new WP_Error('delete_failed', __('Could not remove the old plugin'));
@ -188,7 +192,7 @@ function wp_update_plugin($plugin, $feedback = '') {
apply_filters('update_feedback', __("Installing the latest version"));
// Copy new version of plugin into place.
if ( !copy_dir($working_dir, ABSPATH . PLUGINDIR) ) {
if ( !copy_dir($working_dir, $base . PLUGINDIR) ) {
//$wp_filesystem->delete($working_dir, true);
return new WP_Error('install_failed', __('Installation failed'));
}