<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12723] trunk/wp-admin/includes: Standardise WP_Filesystem_*::put_contents(
 ) arguments to support chmod reliably across all transports.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12723">12723</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-01-14 09:23:53 +0000 (Thu, 14 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Standardise WP_Filesystem_*::put_contents() arguments to support chmod reliably across all transports. Fixes <a href="http://trac.wordpress.org/ticket/10889">#10889</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswpfilesystemdirectphp">trunk/wp-admin/includes/class-wp-filesystem-direct.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemftpextphp">trunk/wp-admin/includes/class-wp-filesystem-ftpext.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemftpsocketsphp">trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php</a></li>
<li><a href="#trunkwpadminincludesclasswpfilesystemssh2php">trunk/wp-admin/includes/class-wp-filesystem-ssh2.php</a></li>
<li><a href="#trunkwpadminincludesfilephp">trunk/wp-admin/includes/file.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpfilesystemdirectphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-direct.php (12722 => 12723)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-direct.php        2010-01-14 02:02:19 UTC (rev 12722)
+++ trunk/wp-admin/includes/class-wp-filesystem-direct.php        2010-01-14 09:23:53 UTC (rev 12723)
</span><span class="lines">@@ -54,14 +54,13 @@
</span><span class="cx">         /**
</span><span class="cx">          * Write a string to a file
</span><span class="cx">          *
</span><del>-         * @param $file string Path to the file where to write the data.
</del><ins>+         * @param $file string Remote path to the file where to write the data.
</ins><span class="cx">          * @param $contents string The data to write.
</span><span class="cx">          * @param $mode int (optional) The file permissions as octal number, usually 0644.
</span><del>-         * @param $type string (optional) Specifies additional type of access you require to the file.
</del><span class="cx">          * @return bool False upon failure.
</span><span class="cx">          */
</span><del>-        function put_contents($file, $contents, $mode = false, $type = '') {
-                if ( ! ($fp = @fopen($file, 'w' . $type)) )
</del><ins>+        function put_contents($file, $contents, $mode = false ) {
+                if ( ! ($fp = @fopen($file, 'w')) )
</ins><span class="cx">                         return false;
</span><span class="cx">                 @fwrite($fp, $contents);
</span><span class="cx">                 @fclose($fp);
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemftpextphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ftpext.php (12722 => 12723)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2010-01-14 02:02:19 UTC (rev 12722)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpext.php        2010-01-14 09:23:53 UTC (rev 12723)
</span><span class="lines">@@ -111,10 +111,8 @@
</span><span class="cx">         function get_contents_array($file) {
</span><span class="cx">                 return explode(&quot;\n&quot;, $this-&gt;get_contents($file));
</span><span class="cx">         }
</span><del>-        function put_contents($file, $contents, $type = '' ) {
-                if ( empty($type) )
-                        $type = $this-&gt;is_binary($contents) ? FTP_BINARY : FTP_ASCII;
-
</del><ins>+        
+        function put_contents($file, $contents, $mode = false ) {
</ins><span class="cx">                 $temp = tmpfile();
</span><span class="cx">                 if ( ! $temp )
</span><span class="cx">                         return false;
</span><span class="lines">@@ -122,9 +120,13 @@
</span><span class="cx">                 fwrite($temp, $contents);
</span><span class="cx">                 fseek($temp, 0); //Skip back to the start of the file being written to
</span><span class="cx"> 
</span><ins>+                $type = $this-&gt;is_binary($contents) ? FTP_BINARY : FTP_ASCII;
</ins><span class="cx">                 $ret = @ftp_fput($this-&gt;link, $file, $temp, $type);
</span><span class="cx"> 
</span><span class="cx">                 fclose($temp);
</span><ins>+
+                $this-&gt;chmod($file, $mode);
+
</ins><span class="cx">                 return $ret;
</span><span class="cx">         }
</span><span class="cx">         function cwd() {
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemftpsocketsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php (12722 => 12723)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2010-01-14 02:02:19 UTC (rev 12722)
+++ trunk/wp-admin/includes/class-wp-filesystem-ftpsockets.php        2010-01-14 09:23:53 UTC (rev 12723)
</span><span class="lines">@@ -115,14 +115,9 @@
</span><span class="cx">                 return explode(&quot;\n&quot;, $this-&gt;get_contents($file) );
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function put_contents($file, $contents, $type = '' ) {
-                if ( empty($type) )
-                        $type = $this-&gt;is_binary($contents) ? FTP_BINARY : FTP_ASCII;
-
-                $this-&gt;ftp-&gt;SetType($type);
-
</del><ins>+        function put_contents($file, $contents, $mode = false ) {
</ins><span class="cx">                 $temp = wp_tempnam( $file );
</span><del>-                if ( ! $temphandle = fopen($temp, 'w+') ) {
</del><ins>+                if ( ! $temphandle = @fopen($temp, 'w+') ) {
</ins><span class="cx">                         unlink($temp);
</span><span class="cx">                         return false;
</span><span class="cx">                 }
</span><span class="lines">@@ -130,10 +125,16 @@
</span><span class="cx">                 fwrite($temphandle, $contents);
</span><span class="cx">                 fseek($temphandle, 0); //Skip back to the start of the file being written to
</span><span class="cx"> 
</span><ins>+                $type = $this-&gt;is_binary($contents) ? FTP_BINARY : FTP_ASCII;
+                $this-&gt;ftp-&gt;SetType($type);
+
</ins><span class="cx">                 $ret = $this-&gt;ftp-&gt;fput($file, $temphandle);
</span><span class="cx"> 
</span><span class="cx">                 fclose($temphandle);
</span><span class="cx">                 unlink($temp);
</span><ins>+
+                $this-&gt;chmod($file, $mode);
+
</ins><span class="cx">                 return $ret;
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludesclasswpfilesystemssh2php"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-filesystem-ssh2.php (12722 => 12723)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-filesystem-ssh2.php        2010-01-14 02:02:19 UTC (rev 12722)
+++ trunk/wp-admin/includes/class-wp-filesystem-ssh2.php        2010-01-14 09:23:53 UTC (rev 12723)
</span><span class="lines">@@ -160,9 +160,13 @@
</span><span class="cx">                 return file('ssh2.sftp://' . $this-&gt;sftp_link . '/' . $file);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function put_contents($file, $contents, $type = '' ) {
</del><ins>+        function put_contents($file, $contents, $mode = false ) {
</ins><span class="cx">                 $file = ltrim($file, '/');
</span><del>-                return false !== file_put_contents('ssh2.sftp://' . $this-&gt;sftp_link . '/' . $file, $contents);
</del><ins>+                $ret = file_put_contents('ssh2.sftp://' . $this-&gt;sftp_link . '/' . $file, $contents);
+
+                $this-&gt;chmod($file, $mode);
+
+                return false !== $ret;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function cwd() {
</span></span></pre></div>
<a id="trunkwpadminincludesfilephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/file.php (12722 => 12723)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/file.php        2010-01-14 02:02:19 UTC (rev 12722)
+++ trunk/wp-admin/includes/file.php        2010-01-14 09:23:53 UTC (rev 12723)
</span><span class="lines">@@ -550,9 +550,8 @@
</span><span class="cx"> 
</span><span class="cx">                 // We've made sure the folders are there, so let's extract the file now:
</span><span class="cx">                 if ( ! $file['folder'] ) {
</span><del>-                        if ( !$fs-&gt;put_contents( $to . $file['filename'], $file['content']) )
</del><ins>+                        if ( !$fs-&gt;put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
</ins><span class="cx">                                 return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
</span><del>-                        $fs-&gt;chmod($to . $file['filename'], FS_CHMOD_FILE);
</del><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">         return true;
</span></span></pre>
</div>
</div>

</body>
</html>