Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Bug #2654 mkdir() should not fail if the directory already exists
Submitted: 2004-10-31 15:36 UTC
From: cellog Assigned: toby
Status: Closed Package: Net_FTP
PHP Version: Irrelevant OS: na
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 36 - 34 = ?

 
 [2004-10-31 15:36 UTC] cellog
Description: ------------ When creating a directory, the goal is for the directory to exist. If the directory already exists, mkdir() fails. This is a problem for recursive directory creation when an absolute path is passed in. A possible solution is to first pwd and save, then attempt to cd to the new dir, and if this succeeds, don't try to create the dir. If it fails, then cd back to saved pwd. I need this fix in order to use Net_FTP for implementing remote install through the PEAR installer. If you don't wish to implement this, I'll just extend Net_FTP and override mkdir(), no big deal.

Comments

 [2004-10-31 18:29 UTC] cellog
Index: Net_FTP/Net/FTP.php =================================================================== RCS file: /repository/pear/Net_FTP/Net/FTP.php,v retrieving revision 1.32 diff -u -r1.32 FTP.php --- Net_FTP/Net/FTP.php 22 Sep 2004 17:38:26 -0000 1.32 +++ Net_FTP/Net/FTP.php 31 Oct 2004 18:28:24 -0000 @@ -752,6 +752,15 @@ function mkdir($dir, $recursive = false) { $dir = $this->_construct_path($dir); + $savedir = $this->pwd(); + $this->pushErrorHandling(PEAR_ERROR_RETURN); + $e = $this->cd($dir); + $this->popErrorHandling(); + if ($e === true) { + $this->cd($savedir); + return true; + } + $this->cd($savedir); if ($recursive === false){ $res = @ftp_mkdir($this->_handle, $dir); if (!$res) { @@ -760,19 +769,14 @@ return true; } } else { - $pos = 0; if(strpos($dir, '/') === false) { return $this->mkdir($dir,false); } - $elements = array(); - while (false !== ($pos = strpos($dir, '/', $pos + 1))){ - $elements[] = substr($dir, 0, $pos); - } - foreach ($elements as $element){ - $res = $this->mkdir($element, false); - if($res !== true) { - return $res; - } + $pos = 0; + $res = $this->mkdir(dirname($dir), true); + $res = $this->mkdir($dir, false); + if ($res !== true) { + return $res; } return true; }
 [2005-01-04 16:21 UTC] toby
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.