mirror of
git://develop.git.wordpress.org/
synced 2025-01-29 18:48:18 +01:00
Standardise WP_Filesystem_*::put_contents() arguments to support chmod reliably across all transports. Fixes #10889
git-svn-id: https://develop.svn.wordpress.org/trunk@12723 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c1f8977b95
commit
76592af8d8
@ -54,14 +54,13 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
/**
|
||||
* Write a string to a file
|
||||
*
|
||||
* @param $file string Path to the file where to write the data.
|
||||
* @param $file string Remote path to the file where to write the data.
|
||||
* @param $contents string The data to write.
|
||||
* @param $mode int (optional) The file permissions as octal number, usually 0644.
|
||||
* @param $type string (optional) Specifies additional type of access you require to the file.
|
||||
* @return bool False upon failure.
|
||||
*/
|
||||
function put_contents($file, $contents, $mode = false, $type = '') {
|
||||
if ( ! ($fp = @fopen($file, 'w' . $type)) )
|
||||
function put_contents($file, $contents, $mode = false ) {
|
||||
if ( ! ($fp = @fopen($file, 'w')) )
|
||||
return false;
|
||||
@fwrite($fp, $contents);
|
||||
@fclose($fp);
|
||||
|
@ -111,10 +111,8 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
||||
function get_contents_array($file) {
|
||||
return explode("\n", $this->get_contents($file));
|
||||
}
|
||||
function put_contents($file, $contents, $type = '' ) {
|
||||
if ( empty($type) )
|
||||
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
|
||||
|
||||
|
||||
function put_contents($file, $contents, $mode = false ) {
|
||||
$temp = tmpfile();
|
||||
if ( ! $temp )
|
||||
return false;
|
||||
@ -122,9 +120,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
|
||||
fwrite($temp, $contents);
|
||||
fseek($temp, 0); //Skip back to the start of the file being written to
|
||||
|
||||
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
|
||||
$ret = @ftp_fput($this->link, $file, $temp, $type);
|
||||
|
||||
fclose($temp);
|
||||
|
||||
$this->chmod($file, $mode);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
function cwd() {
|
||||
|
@ -115,14 +115,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
||||
return explode("\n", $this->get_contents($file) );
|
||||
}
|
||||
|
||||
function put_contents($file, $contents, $type = '' ) {
|
||||
if ( empty($type) )
|
||||
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
|
||||
|
||||
$this->ftp->SetType($type);
|
||||
|
||||
function put_contents($file, $contents, $mode = false ) {
|
||||
$temp = wp_tempnam( $file );
|
||||
if ( ! $temphandle = fopen($temp, 'w+') ) {
|
||||
if ( ! $temphandle = @fopen($temp, 'w+') ) {
|
||||
unlink($temp);
|
||||
return false;
|
||||
}
|
||||
@ -130,10 +125,16 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
|
||||
fwrite($temphandle, $contents);
|
||||
fseek($temphandle, 0); //Skip back to the start of the file being written to
|
||||
|
||||
$type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII;
|
||||
$this->ftp->SetType($type);
|
||||
|
||||
$ret = $this->ftp->fput($file, $temphandle);
|
||||
|
||||
fclose($temphandle);
|
||||
unlink($temp);
|
||||
|
||||
$this->chmod($file, $mode);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@ -160,9 +160,13 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
|
||||
return file('ssh2.sftp://' . $this->sftp_link . '/' . $file);
|
||||
}
|
||||
|
||||
function put_contents($file, $contents, $type = '' ) {
|
||||
function put_contents($file, $contents, $mode = false ) {
|
||||
$file = ltrim($file, '/');
|
||||
return false !== file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
|
||||
$ret = file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
|
||||
|
||||
$this->chmod($file, $mode);
|
||||
|
||||
return false !== $ret;
|
||||
}
|
||||
|
||||
function cwd() {
|
||||
|
@ -550,9 +550,8 @@ function unzip_file($file, $to) {
|
||||
|
||||
// We've made sure the folders are there, so let's extract the file now:
|
||||
if ( ! $file['folder'] ) {
|
||||
if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
|
||||
if ( !$fs->put_contents( $to . $file['filename'], $file['content'], FS_CHMOD_FILE) )
|
||||
return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
|
||||
$fs->chmod($to . $file['filename'], FS_CHMOD_FILE);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user