[wp-trac] [WordPress Trac] #10831: Autoupgrade: Synchronous FTP client fails while plugin upgrade/installation (on some systems)
WordPress Trac
wp-trac at lists.automattic.com
Wed Sep 23 22:34:23 UTC 2009
#10831: Autoupgrade: Synchronous FTP client fails while plugin upgrade/installation
(on some systems)
--------------------------+-------------------------------------------------
Reporter: darkman82 | Owner: dd32
Type: defect (bug) | Status: new
Priority: normal | Milestone: 2.9
Component: Filesystem | Version: 2.8.4
Severity: normal | Keywords: reporer-feedback
--------------------------+-------------------------------------------------
Comment(by darkman82):
Replying to [comment:1 dd32]:
> Would it be possible for you to explain the changes you've made? ie
"Instead of looking for bar, It looks for foo Followed by bar"
>
> Also, attaching a diff of WordPress Trunk SVN would be appreciated, But
if you cant do that, I can create a new patch from yours late for
comparison.
I just added a kind of buffered text reader in class-ftp-sockets.php, I
changed only _readmsg function and added a line in _exec function:
BEFORE:
{{{
function _readmsg($fnction="_readmsg"){
if(!$this->_connected) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
$result=true;
$this->_message="";
$this->_code=0;
$go=true;
do {
$tmp=@socket_read($this->_ftp_control_sock, 4096,
PHP_BINARY_READ);
if($tmp===false) {
$go=$result=false;
$this->PushError($fnction,'Read failed',
socket_strerror(socket_last_error($this->_ftp_control_sock)));
} else {
$this->_message.=$tmp;
$go = !preg_match("/^([0-9]{3})(-.+\\1)?
[^".CRLF."]+".CRLF."$/Us", $this->_message, $regs);
}
} while($go);
if($this->LocalEcho) echo "GET < ".rtrim($this->_message,
CRLF).CRLF;
$this->_code=(int)$regs[1];
return $result;
}
function _exec($cmd, $fnction="_exec") {
if(!$this->_ready) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
$status=@socket_write($this->_ftp_control_sock,
$cmd.CRLF);
if($status===false) {
$this->PushError($fnction,'socket write failed',
socket_strerror(socket_last_error($this->stream)));
return FALSE;
}
$this->_lastaction=time();
if(!$this->_readmsg($fnction)) return FALSE;
return TRUE;
}
}}}
AFTER:
{{{
function _readmsg($fnction="_readmsg"){
if(!$this->_connected) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
$result=true;
$this->_message="";
$this->_code=0;
// Read until at least ONE line is available
while( ($pos = strpos($this->_buffz, CRLF))===false ){
$tmp=@socket_read($this->_ftp_control_sock, 4096,
PHP_BINARY_READ);
if($tmp===false){
$this->PushError($fnction,'Read failed',
socket_strerror(socket_last_error($this->_ftp_control_sock)));
return FALSE;
}
$this->_buffz.=$tmp;
}
$this->_message = substr($this->_buffz,0,$pos).CRLF;
$this->_buffz = substr($this->_buffz,$pos+strlen(CRLF));
if( !preg_match("/^([0-9]{3})(-.+\\1)?
.+$/Us",$this->_message, $regs))
return ($this->_readmsg($fnction));
if($this->LocalEcho) echo "GET < ".rtrim($this->_message,
CRLF).CRLF;
$this->_code=(int)$regs[1];
return $result;
}
function _exec($cmd, $fnction="_exec") {
if(!$this->_ready) {
$this->PushError($fnction,'Connect first');
return FALSE;
}
if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
$this->_buffz=""; // ADDED
$status=@socket_write($this->_ftp_control_sock,
$cmd.CRLF);
if($status===false) {
$this->PushError($fnction,'socket write failed',
socket_strerror(socket_last_error($this->stream)));
return FALSE;
}
$this->_lastaction=time();
if(!$this->_readmsg($fnction)) return FALSE;
return TRUE;
}
}}}
That's all.
You can see the "patched" file here:
http://darkman.it/x/class-ftp-sockets.php.txt
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10831#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list