Coding Standards: Add some space around control structures in WP_Filesystem_* classes for consistency and better readability.

Additionally, synchronize `$tempfile` and `$temphandle` variable names in `WP_Filesystem_FTPext` and `WP_Filesystem_ftpsockets`.

See #49542.
Built from https://develop.svn.wordpress.org/trunk@48089


git-svn-id: http://core.svn.wordpress.org/trunk@47856 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-06-19 10:36:12 +00:00
parent 1e3d4921fb
commit 527696af3b
6 changed files with 194 additions and 28 deletions

View File

@ -55,11 +55,13 @@ class WP_Filesystem_Base {
*/ */
public function abspath() { public function abspath() {
$folder = $this->find_folder( ABSPATH ); $folder = $this->find_folder( ABSPATH );
// Perhaps the FTP folder is rooted at the WordPress install. // Perhaps the FTP folder is rooted at the WordPress install.
// Check for wp-includes folder in root. Could have some false positives, but rare. // Check for wp-includes folder in root. Could have some false positives, but rare.
if ( ! $folder && $this->is_dir( '/' . WPINC ) ) { if ( ! $folder && $this->is_dir( '/' . WPINC ) ) {
$folder = '/'; $folder = '/';
} }
return $folder; return $folder;
} }
@ -188,6 +190,7 @@ class WP_Filesystem_Base {
if ( ! defined( $constant ) ) { if ( ! defined( $constant ) ) {
continue; continue;
} }
if ( $folder === $dir ) { if ( $folder === $dir ) {
return trailingslashit( constant( $constant ) ); return trailingslashit( constant( $constant ) );
} }
@ -198,18 +201,21 @@ class WP_Filesystem_Base {
if ( ! defined( $constant ) ) { if ( ! defined( $constant ) ) {
continue; continue;
} }
if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir. if ( 0 === stripos( $folder, $dir ) ) { // $folder starts with $dir.
$potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder ); $potential_folder = preg_replace( '#^' . preg_quote( $dir, '#' ) . '/#i', trailingslashit( constant( $constant ) ), $folder );
$potential_folder = trailingslashit( $potential_folder ); $potential_folder = trailingslashit( $potential_folder );
if ( $this->is_dir( $potential_folder ) ) { if ( $this->is_dir( $potential_folder ) ) {
$this->cache[ $folder ] = $potential_folder; $this->cache[ $folder ] = $potential_folder;
return $potential_folder; return $potential_folder;
} }
} }
} }
} elseif ( 'direct' === $this->method ) { } elseif ( 'direct' === $this->method ) {
$folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation. $folder = str_replace( '\\', '/', $folder ); // Windows path sanitisation.
return trailingslashit( $folder ); return trailingslashit( $folder );
} }
@ -223,12 +229,16 @@ class WP_Filesystem_Base {
if ( $this->exists( $folder ) ) { // Folder exists at that absolute path. if ( $this->exists( $folder ) ) { // Folder exists at that absolute path.
$folder = trailingslashit( $folder ); $folder = trailingslashit( $folder );
$this->cache[ $folder ] = $folder; $this->cache[ $folder ] = $folder;
return $folder; return $folder;
} }
$return = $this->search_for_folder( $folder ); $return = $this->search_for_folder( $folder );
if ( $return ) { if ( $return ) {
$this->cache[ $folder ] = $return; $this->cache[ $folder ] = $return;
} }
return $return; return $return;
} }
@ -279,6 +289,7 @@ class WP_Filesystem_Base {
// Let's try that folder: // Let's try that folder:
$newdir = trailingslashit( path_join( $base, $key ) ); $newdir = trailingslashit( path_join( $base, $key ) );
if ( $this->verbose ) { if ( $this->verbose ) {
/* translators: %s: Directory name. */ /* translators: %s: Directory name. */
printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir ); printf( "\n" . __( 'Changing to %s' ) . "<br/>\n", $newdir );
@ -287,6 +298,7 @@ class WP_Filesystem_Base {
// Only search for the remaining path tokens in the directory, not the full path again. // Only search for the remaining path tokens in the directory, not the full path again.
$newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) ); $newfolder = implode( '/', array_slice( $folder_parts, $index + 1 ) );
$ret = $this->search_for_folder( $newfolder, $newdir, $loop ); $ret = $this->search_for_folder( $newfolder, $newdir, $loop );
if ( $ret ) { if ( $ret ) {
return $ret; return $ret;
} }
@ -300,6 +312,7 @@ class WP_Filesystem_Base {
/* translators: %s: Directory name. */ /* translators: %s: Directory name. */
printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path ); printf( "\n" . __( 'Found %s' ) . "<br/>\n", $base . $last_path );
} }
return trailingslashit( $base . $last_path ); return trailingslashit( $base . $last_path );
} }
@ -329,6 +342,7 @@ class WP_Filesystem_Base {
*/ */
public function gethchmod( $file ) { public function gethchmod( $file ) {
$perms = intval( $this->getchmod( $file ), 8 ); $perms = intval( $this->getchmod( $file ), 8 );
if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket. if ( ( $perms & 0xC000 ) == 0xC000 ) { // Socket.
$info = 's'; $info = 's';
} elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link. } elseif ( ( $perms & 0xA000 ) == 0xA000 ) { // Symbolic Link.
@ -367,6 +381,7 @@ class WP_Filesystem_Base {
$info .= ( ( $perms & 0x0001 ) ? $info .= ( ( $perms & 0x0001 ) ?
( ( $perms & 0x0200 ) ? 't' : 'x' ) : ( ( $perms & 0x0200 ) ? 't' : 'x' ) :
( ( $perms & 0x0200 ) ? 'T' : '-' ) ); ( ( $perms & 0x0200 ) ? 'T' : '-' ) );
return $info; return $info;
} }
@ -402,6 +417,7 @@ class WP_Filesystem_Base {
for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) { for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
$key = array_search( $attarray[ $i ], $legal, true ); $key = array_search( $attarray[ $i ], $legal, true );
if ( $key ) { if ( $key ) {
$realmode .= $legal[ $key ]; $realmode .= $legal[ $key ];
} }
@ -420,6 +436,7 @@ class WP_Filesystem_Base {
$newmode .= $mode[1] + $mode[2] + $mode[3]; $newmode .= $mode[1] + $mode[2] + $mode[3];
$newmode .= $mode[4] + $mode[5] + $mode[6]; $newmode .= $mode[4] + $mode[5] + $mode[6];
$newmode .= $mode[7] + $mode[8] + $mode[9]; $newmode .= $mode[7] + $mode[8] + $mode[9];
return $newmode; return $newmode;
} }

View File

@ -64,6 +64,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
*/ */
public function put_contents( $file, $contents, $mode = false ) { public function put_contents( $file, $contents, $mode = false ) {
$fp = @fopen( $file, 'wb' ); $fp = @fopen( $file, 'wb' );
if ( ! $fp ) { if ( ! $fp ) {
return false; return false;
} }
@ -125,15 +126,19 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( ! $this->exists( $file ) ) { if ( ! $this->exists( $file ) ) {
return false; return false;
} }
if ( ! $recursive ) { if ( ! $recursive ) {
return chgrp( $file, $group ); return chgrp( $file, $group );
} }
if ( ! $this->is_dir( $file ) ) { if ( ! $this->is_dir( $file ) ) {
return chgrp( $file, $group ); return chgrp( $file, $group );
} }
// Is a directory, and we want recursive. // Is a directory, and we want recursive.
$file = trailingslashit( $file ); $file = trailingslashit( $file );
$filelist = $this->dirlist( $file ); $filelist = $this->dirlist( $file );
foreach ( $filelist as $filename ) { foreach ( $filelist as $filename ) {
$this->chgrp( $file . $filename, $group, $recursive ); $this->chgrp( $file . $filename, $group, $recursive );
} }
@ -167,9 +172,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( ! $recursive || ! $this->is_dir( $file ) ) { if ( ! $recursive || ! $this->is_dir( $file ) ) {
return chmod( $file, $mode ); return chmod( $file, $mode );
} }
// Is a directory, and we want recursive. // Is a directory, and we want recursive.
$file = trailingslashit( $file ); $file = trailingslashit( $file );
$filelist = $this->dirlist( $file ); $filelist = $this->dirlist( $file );
foreach ( (array) $filelist as $filename => $filemeta ) { foreach ( (array) $filelist as $filename => $filemeta ) {
$this->chmod( $file . $filename, $mode, $recursive ); $this->chmod( $file . $filename, $mode, $recursive );
} }
@ -192,17 +199,22 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( ! $this->exists( $file ) ) { if ( ! $this->exists( $file ) ) {
return false; return false;
} }
if ( ! $recursive ) { if ( ! $recursive ) {
return chown( $file, $owner ); return chown( $file, $owner );
} }
if ( ! $this->is_dir( $file ) ) { if ( ! $this->is_dir( $file ) ) {
return chown( $file, $owner ); return chown( $file, $owner );
} }
// Is a directory, and we want recursive. // Is a directory, and we want recursive.
$filelist = $this->dirlist( $file ); $filelist = $this->dirlist( $file );
foreach ( $filelist as $filename ) { foreach ( $filelist as $filename ) {
$this->chown( $file . '/' . $filename, $owner, $recursive ); $this->chown( $file . '/' . $filename, $owner, $recursive );
} }
return true; return true;
} }
@ -216,16 +228,21 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
*/ */
public function owner( $file ) { public function owner( $file ) {
$owneruid = @fileowner( $file ); $owneruid = @fileowner( $file );
if ( ! $owneruid ) { if ( ! $owneruid ) {
return false; return false;
} }
if ( ! function_exists( 'posix_getpwuid' ) ) { if ( ! function_exists( 'posix_getpwuid' ) ) {
return $owneruid; return $owneruid;
} }
$ownerarray = posix_getpwuid( $owneruid ); $ownerarray = posix_getpwuid( $owneruid );
if ( ! $ownerarray ) { if ( ! $ownerarray ) {
return false; return false;
} }
return $ownerarray['name']; return $ownerarray['name'];
} }
@ -253,16 +270,21 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
*/ */
public function group( $file ) { public function group( $file ) {
$gid = @filegroup( $file ); $gid = @filegroup( $file );
if ( ! $gid ) { if ( ! $gid ) {
return false; return false;
} }
if ( ! function_exists( 'posix_getgrgid' ) ) { if ( ! function_exists( 'posix_getgrgid' ) ) {
return $gid; return $gid;
} }
$grouparray = posix_getgrgid( $gid ); $grouparray = posix_getgrgid( $gid );
if ( ! $grouparray ) { if ( ! $grouparray ) {
return false; return false;
} }
return $grouparray['name']; return $grouparray['name'];
} }
@ -285,9 +307,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
} }
$rtval = copy( $source, $destination ); $rtval = copy( $source, $destination );
if ( $mode ) { if ( $mode ) {
$this->chmod( $destination, $mode ); $this->chmod( $destination, $mode );
} }
return $rtval; return $rtval;
} }
@ -314,6 +338,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) { if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) {
$this->delete( $source ); $this->delete( $source );
return true; return true;
} else { } else {
return false; return false;
@ -337,11 +362,13 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
// Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem.
return false; return false;
} }
$file = str_replace( '\\', '/', $file ); // For Win32, occasional problems deleting files otherwise. $file = str_replace( '\\', '/', $file ); // For Win32, occasional problems deleting files otherwise.
if ( 'f' === $type || $this->is_file( $file ) ) { if ( 'f' === $type || $this->is_file( $file ) ) {
return @unlink( $file ); return @unlink( $file );
} }
if ( ! $recursive && $this->is_dir( $file ) ) { if ( ! $recursive && $this->is_dir( $file ) ) {
return @rmdir( $file ); return @rmdir( $file );
} }
@ -351,6 +378,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
$filelist = $this->dirlist( $file, true ); $filelist = $this->dirlist( $file, true );
$retval = true; $retval = true;
if ( is_array( $filelist ) ) { if ( is_array( $filelist ) ) {
foreach ( $filelist as $filename => $fileinfo ) { foreach ( $filelist as $filename => $fileinfo ) {
if ( ! $this->delete( $file . $filename, $recursive, $fileinfo['type'] ) ) { if ( ! $this->delete( $file . $filename, $recursive, $fileinfo['type'] ) ) {
@ -480,9 +508,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( 0 == $time ) { if ( 0 == $time ) {
$time = time(); $time = time();
} }
if ( 0 == $atime ) { if ( 0 == $atime ) {
$atime = time(); $atime = time();
} }
return touch( $file, $time, $atime ); return touch( $file, $time, $atime );
} }
@ -503,6 +533,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
// Safe mode fails with a trailing slash under certain PHP versions. // Safe mode fails with a trailing slash under certain PHP versions.
$path = untrailingslashit( $path ); $path = untrailingslashit( $path );
if ( empty( $path ) ) { if ( empty( $path ) ) {
return false; return false;
} }
@ -514,13 +545,17 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
if ( ! @mkdir( $path ) ) { if ( ! @mkdir( $path ) ) {
return false; return false;
} }
$this->chmod( $path, $chmod ); $this->chmod( $path, $chmod );
if ( $chown ) { if ( $chown ) {
$this->chown( $path, $chown ); $this->chown( $path, $chown );
} }
if ( $chgrp ) { if ( $chgrp ) {
$this->chgrp( $path, $chgrp ); $this->chgrp( $path, $chgrp );
} }
return true; return true;
} }
@ -576,6 +611,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
} }
$dir = dir( $path ); $dir = dir( $path );
if ( ! $dir ) { if ( ! $dir ) {
return false; return false;
} }
@ -619,8 +655,10 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
$ret[ $struc['name'] ] = $struc; $ret[ $struc['name'] ] = $struc;
} }
$dir->close(); $dir->close();
unset( $dir ); unset( $dir );
return $ret; return $ret;
} }
} }

View File

@ -69,6 +69,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
} }
$this->options['ssl'] = false; $this->options['ssl'] = false;
if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) { if ( isset( $opt['connection_type'] ) && 'ftps' === $opt['connection_type'] ) {
$this->options['ssl'] = true; $this->options['ssl'] = true;
} }
@ -97,6 +98,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$this->options['hostname'] . ':' . $this->options['port'] $this->options['hostname'] . ':' . $this->options['port']
) )
); );
return false; return false;
} }
@ -109,11 +111,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$this->options['username'] $this->options['username']
) )
); );
return false; return false;
} }
// Set the connection to use Passive FTP. // Set the connection to use Passive FTP.
ftp_pasv( $this->link, true ); ftp_pasv( $this->link, true );
if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) { if ( @ftp_get_option( $this->link, FTP_TIMEOUT_SEC ) < FS_TIMEOUT ) {
@ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT ); @ftp_set_option( $this->link, FTP_TIMEOUT_SEC, FS_TIMEOUT );
} }
@ -132,28 +136,29 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function get_contents( $file ) { public function get_contents( $file ) {
$tempfile = wp_tempnam( $file ); $tempfile = wp_tempnam( $file );
$temp = fopen( $tempfile, 'w+' ); $temphandle = fopen( $tempfile, 'w+' );
if ( ! $temp ) { if ( ! $temphandle ) {
unlink( $tempfile ); unlink( $tempfile );
return false; return false;
} }
if ( ! ftp_fget( $this->link, $temp, $file, FTP_BINARY ) ) { if ( ! ftp_fget( $this->link, $temphandle, $file, FTP_BINARY ) ) {
fclose( $temp ); fclose( $temphandle );
unlink( $tempfile ); unlink( $tempfile );
return false; return false;
} }
fseek( $temp, 0 ); // Skip back to the start of the file being written to. fseek( $temphandle, 0 ); // Skip back to the start of the file being written to.
$contents = ''; $contents = '';
while ( ! feof( $temp ) ) { while ( ! feof( $temphandle ) ) {
$contents .= fread( $temp, 8 * KB_IN_BYTES ); $contents .= fread( $temphandle, 8 * KB_IN_BYTES );
} }
fclose( $temp ); fclose( $temphangle );
unlink( $tempfile ); unlink( $tempfile );
return $contents; return $contents;
} }
@ -182,9 +187,9 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function put_contents( $file, $contents, $mode = false ) { public function put_contents( $file, $contents, $mode = false ) {
$tempfile = wp_tempnam( $file ); $tempfile = wp_tempnam( $file );
$temp = fopen( $tempfile, 'wb+' ); $temphandle = fopen( $tempfile, 'wb+' );
if ( ! $temp ) { if ( ! $temphandle ) {
unlink( $tempfile ); unlink( $tempfile );
return false; return false;
} }
@ -192,21 +197,21 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
mbstring_binary_safe_encoding(); mbstring_binary_safe_encoding();
$data_length = strlen( $contents ); $data_length = strlen( $contents );
$bytes_written = fwrite( $temp, $contents ); $bytes_written = fwrite( $temphandle, $contents );
reset_mbstring_encoding(); reset_mbstring_encoding();
if ( $data_length !== $bytes_written ) { if ( $data_length !== $bytes_written ) {
fclose( $temp ); fclose( $temphandle );
unlink( $tempfile ); unlink( $tempfile );
return false; return false;
} }
fseek( $temp, 0 ); // Skip back to the start of the file being written to. fseek( $temphandle, 0 ); // Skip back to the start of the file being written to.
$ret = ftp_fput( $this->link, $file, $temp, FTP_BINARY ); $ret = ftp_fput( $this->link, $file, $temphandle, FTP_BINARY );
fclose( $temp ); fclose( $temphandle );
unlink( $tempfile ); unlink( $tempfile );
$this->chmod( $file, $mode ); $this->chmod( $file, $mode );
@ -223,9 +228,11 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function cwd() { public function cwd() {
$cwd = ftp_pwd( $this->link ); $cwd = ftp_pwd( $this->link );
if ( $cwd ) { if ( $cwd ) {
$cwd = trailingslashit( $cwd ); $cwd = trailingslashit( $cwd );
} }
return $cwd; return $cwd;
} }
@ -267,6 +274,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
// chmod any sub-objects if recursive. // chmod any sub-objects if recursive.
if ( $recursive && $this->is_dir( $file ) ) { if ( $recursive && $this->is_dir( $file ) ) {
$filelist = $this->dirlist( $file ); $filelist = $this->dirlist( $file );
foreach ( (array) $filelist as $filename => $filemeta ) { foreach ( (array) $filelist as $filename => $filemeta ) {
$this->chmod( $file . '/' . $filename, $mode, $recursive ); $this->chmod( $file . '/' . $filename, $mode, $recursive );
} }
@ -276,6 +284,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( ! function_exists( 'ftp_chmod' ) ) { if ( ! function_exists( 'ftp_chmod' ) ) {
return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) ); return (bool) ftp_site( $this->link, sprintf( 'CHMOD %o %s', $mode, $file ) );
} }
return (bool) ftp_chmod( $this->link, $mode, $file ); return (bool) ftp_chmod( $this->link, $mode, $file );
} }
@ -289,6 +298,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function owner( $file ) { public function owner( $file ) {
$dir = $this->dirlist( $file ); $dir = $this->dirlist( $file );
return $dir[ $file ]['owner']; return $dir[ $file ]['owner'];
} }
@ -302,6 +312,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function getchmod( $file ) { public function getchmod( $file ) {
$dir = $this->dirlist( $file ); $dir = $this->dirlist( $file );
return $dir[ $file ]['permsn']; return $dir[ $file ]['permsn'];
} }
@ -315,6 +326,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function group( $file ) { public function group( $file ) {
$dir = $this->dirlist( $file ); $dir = $this->dirlist( $file );
return $dir[ $file ]['group']; return $dir[ $file ]['group'];
} }
@ -335,10 +347,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( ! $overwrite && $this->exists( $destination ) ) { if ( ! $overwrite && $this->exists( $destination ) ) {
return false; return false;
} }
$content = $this->get_contents( $source ); $content = $this->get_contents( $source );
if ( false === $content ) { if ( false === $content ) {
return false; return false;
} }
return $this->put_contents( $destination, $content, $mode ); return $this->put_contents( $destination, $content, $mode );
} }
@ -373,19 +388,23 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( empty( $file ) ) { if ( empty( $file ) ) {
return false; return false;
} }
if ( 'f' === $type || $this->is_file( $file ) ) { if ( 'f' === $type || $this->is_file( $file ) ) {
return ftp_delete( $this->link, $file ); return ftp_delete( $this->link, $file );
} }
if ( ! $recursive ) { if ( ! $recursive ) {
return ftp_rmdir( $this->link, $file ); return ftp_rmdir( $this->link, $file );
} }
$filelist = $this->dirlist( trailingslashit( $file ) ); $filelist = $this->dirlist( trailingslashit( $file ) );
if ( ! empty( $filelist ) ) { if ( ! empty( $filelist ) ) {
foreach ( $filelist as $delete_file ) { foreach ( $filelist as $delete_file ) {
$this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] ); $this->delete( trailingslashit( $file ) . $delete_file['name'], $recursive, $delete_file['type'] );
} }
} }
return ftp_rmdir( $this->link, $file ); return ftp_rmdir( $this->link, $file );
} }
@ -430,10 +449,12 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
public function is_dir( $path ) { public function is_dir( $path ) {
$cwd = $this->cwd(); $cwd = $this->cwd();
$result = @ftp_chdir( $this->link, trailingslashit( $path ) ); $result = @ftp_chdir( $this->link, trailingslashit( $path ) );
if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { if ( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
@ftp_chdir( $this->link, $cwd ); @ftp_chdir( $this->link, $cwd );
return true; return true;
} }
return false; return false;
} }
@ -531,6 +552,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path ); $path = untrailingslashit( $path );
if ( empty( $path ) ) { if ( empty( $path ) ) {
return false; return false;
} }
@ -538,7 +560,9 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
if ( ! ftp_mkdir( $this->link, $path ) ) { if ( ! ftp_mkdir( $this->link, $path ) ) {
return false; return false;
} }
$this->chmod( $path, $chmod ); $this->chmod( $path, $chmod );
return true; return true;
} }
@ -563,23 +587,28 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
*/ */
public function parselisting( $line ) { public function parselisting( $line ) {
static $is_windows = null; static $is_windows = null;
if ( is_null( $is_windows ) ) { if ( is_null( $is_windows ) ) {
$is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false; $is_windows = stripos( ftp_systype( $this->link ), 'win' ) !== false;
} }
if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) { if ( $is_windows && preg_match( '/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/', $line, $lucifer ) ) {
$b = array(); $b = array();
if ( $lucifer[3] < 70 ) { if ( $lucifer[3] < 70 ) {
$lucifer[3] += 2000; $lucifer[3] += 2000;
} else { } else {
$lucifer[3] += 1900; // 4-digit year fix. $lucifer[3] += 1900; // 4-digit year fix.
} }
$b['isdir'] = ( '<DIR>' === $lucifer[7] ); $b['isdir'] = ( '<DIR>' === $lucifer[7] );
if ( $b['isdir'] ) { if ( $b['isdir'] ) {
$b['type'] = 'd'; $b['type'] = 'd';
} else { } else {
$b['type'] = 'f'; $b['type'] = 'f';
} }
$b['size'] = $lucifer[7]; $b['size'] = $lucifer[7];
$b['month'] = $lucifer[1]; $b['month'] = $lucifer[1];
$b['day'] = $lucifer[2]; $b['day'] = $lucifer[2];
@ -591,15 +620,19 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$b['name'] = $lucifer[8]; $b['name'] = $lucifer[8];
} elseif ( ! $is_windows ) { } elseif ( ! $is_windows ) {
$lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY ); $lucifer = preg_split( '/[ ]/', $line, 9, PREG_SPLIT_NO_EMPTY );
if ( $lucifer ) { if ( $lucifer ) {
// echo $line."\n"; // echo $line."\n";
$lcount = count( $lucifer ); $lcount = count( $lucifer );
if ( $lcount < 8 ) { if ( $lcount < 8 ) {
return ''; return '';
} }
$b = array(); $b = array();
$b['isdir'] = 'd' === $lucifer[0][0]; $b['isdir'] = 'd' === $lucifer[0][0];
$b['islink'] = 'l' === $lucifer[0][0]; $b['islink'] = 'l' === $lucifer[0][0];
if ( $b['isdir'] ) { if ( $b['isdir'] ) {
$b['type'] = 'd'; $b['type'] = 'd';
} elseif ( $b['islink'] ) { } elseif ( $b['islink'] ) {
@ -607,20 +640,24 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
} else { } else {
$b['type'] = 'f'; $b['type'] = 'f';
} }
$b['perms'] = $lucifer[0]; $b['perms'] = $lucifer[0];
$b['permsn'] = $this->getnumchmodfromh( $b['perms'] ); $b['permsn'] = $this->getnumchmodfromh( $b['perms'] );
$b['number'] = $lucifer[1]; $b['number'] = $lucifer[1];
$b['owner'] = $lucifer[2]; $b['owner'] = $lucifer[2];
$b['group'] = $lucifer[3]; $b['group'] = $lucifer[3];
$b['size'] = $lucifer[4]; $b['size'] = $lucifer[4];
if ( 8 == $lcount ) { if ( 8 == $lcount ) {
sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] ); sscanf( $lucifer[5], '%d-%d-%d', $b['year'], $b['month'], $b['day'] );
sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] ); sscanf( $lucifer[6], '%d:%d', $b['hour'], $b['minute'] );
$b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] ); $b['time'] = mktime( $b['hour'], $b['minute'], 0, $b['month'], $b['day'], $b['year'] );
$b['name'] = $lucifer[7]; $b['name'] = $lucifer[7];
} else { } else {
$b['month'] = $lucifer[5]; $b['month'] = $lucifer[5];
$b['day'] = $lucifer[6]; $b['day'] = $lucifer[6];
if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) { if ( preg_match( '/([0-9]{2}):([0-9]{2})/', $lucifer[7], $l2 ) ) {
$b['year'] = gmdate( 'Y' ); $b['year'] = gmdate( 'Y' );
$b['hour'] = $l2[1]; $b['hour'] = $l2[1];
@ -630,6 +667,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$b['hour'] = 0; $b['hour'] = 0;
$b['minute'] = 0; $b['minute'] = 0;
} }
$b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) ); $b['time'] = strtotime( sprintf( '%d %s %d %02d:%02d', $b['day'], $b['month'], $b['year'], $b['hour'], $b['minute'] ) );
$b['name'] = $lucifer[8]; $b['name'] = $lucifer[8];
} }
@ -678,10 +716,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
} }
$pwd = ftp_pwd( $this->link ); $pwd = ftp_pwd( $this->link );
if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist. if ( ! @ftp_chdir( $this->link, $path ) ) { // Can't change to folder = folder doesn't exist.
return false; return false;
} }
$list = ftp_rawlist( $this->link, '-a', false ); $list = ftp_rawlist( $this->link, '-a', false );
@ftp_chdir( $this->link, $pwd ); @ftp_chdir( $this->link, $pwd );
if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least). if ( empty( $list ) ) { // Empty array = non-existent folder (real folder will show . at least).
@ -689,8 +730,10 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
} }
$dirlist = array(); $dirlist = array();
foreach ( $list as $k => $v ) { foreach ( $list as $k => $v ) {
$entry = $this->parselisting( $v ); $entry = $this->parselisting( $v );
if ( empty( $entry ) ) { if ( empty( $entry ) ) {
continue; continue;
} }
@ -711,6 +754,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
} }
$ret = array(); $ret = array();
foreach ( (array) $dirlist as $struc ) { foreach ( (array) $dirlist as $struc ) {
if ( 'd' === $struc['type'] ) { if ( 'd' === $struc['type'] ) {
if ( $recursive ) { if ( $recursive ) {
@ -722,6 +766,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$ret[ $struc['name'] ] = $struc; $ret[ $struc['name'] ] = $struc;
} }
return $ret; return $ret;
} }

View File

@ -36,6 +36,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( ! include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) { if ( ! include_once ABSPATH . 'wp-admin/includes/class-ftp.php' ) {
return; return;
} }
$this->ftp = new ftp(); $this->ftp = new ftp();
if ( empty( $opt['port'] ) ) { if ( empty( $opt['port'] ) ) {
@ -87,6 +88,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$this->options['hostname'] . ':' . $this->options['port'] $this->options['hostname'] . ':' . $this->options['port']
) )
); );
return false; return false;
} }
@ -99,6 +101,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$this->options['hostname'] . ':' . $this->options['port'] $this->options['hostname'] . ':' . $this->options['port']
) )
); );
return false; return false;
} }
@ -111,12 +114,14 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
$this->options['username'] $this->options['username']
) )
); );
return false; return false;
} }
$this->ftp->SetType( FTP_BINARY ); $this->ftp->SetType( FTP_BINARY );
$this->ftp->Passive( true ); $this->ftp->Passive( true );
$this->ftp->setTimeout( FS_TIMEOUT ); $this->ftp->setTimeout( FS_TIMEOUT );
return true; return true;
} }
@ -134,11 +139,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return false; return false;
} }
$temp = wp_tempnam( $file ); $tempfile = wp_tempnam( $file );
$temphandle = fopen( $tempfile, 'w+' );
$temphandle = fopen( $temp, 'w+' );
if ( ! $temphandle ) { if ( ! $temphandle ) {
unlink( $temp ); unlink( $tempfile );
return false; return false;
} }
@ -146,7 +151,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( ! $this->ftp->fget( $temphandle, $file ) ) { if ( ! $this->ftp->fget( $temphandle, $file ) ) {
fclose( $temphandle ); fclose( $temphandle );
unlink( $temp ); unlink( $tempfile );
reset_mbstring_encoding(); reset_mbstring_encoding();
@ -163,7 +168,8 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
} }
fclose( $temphandle ); fclose( $temphandle );
unlink( $temp ); unlink( $tempfile );
return $contents; return $contents;
} }
@ -191,10 +197,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
* @return bool True on success, false on failure. * @return bool True on success, false on failure.
*/ */
public function put_contents( $file, $contents, $mode = false ) { public function put_contents( $file, $contents, $mode = false ) {
$temp = wp_tempnam( $file ); $tempfile = wp_tempnam( $file );
$temphandle = @fopen( $temp, 'w+' ); $temphandle = @fopen( $tempfile, 'w+' );
if ( ! $temphandle ) { if ( ! $temphandle ) {
unlink( $temp ); unlink( $tempfile );
return false; return false;
} }
@ -202,9 +209,10 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
mbstring_binary_safe_encoding(); mbstring_binary_safe_encoding();
$bytes_written = fwrite( $temphandle, $contents ); $bytes_written = fwrite( $temphandle, $contents );
if ( false === $bytes_written || strlen( $contents ) != $bytes_written ) { if ( false === $bytes_written || strlen( $contents ) != $bytes_written ) {
fclose( $temphandle ); fclose( $temphandle );
unlink( $temp ); unlink( $tempfile );
reset_mbstring_encoding(); reset_mbstring_encoding();
@ -218,7 +226,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
reset_mbstring_encoding(); reset_mbstring_encoding();
fclose( $temphandle ); fclose( $temphandle );
unlink( $temp ); unlink( $tempfile );
$this->chmod( $file, $mode ); $this->chmod( $file, $mode );
@ -234,9 +242,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
*/ */
public function cwd() { public function cwd() {
$cwd = $this->ftp->pwd(); $cwd = $this->ftp->pwd();
if ( $cwd ) { if ( $cwd ) {
$cwd = trailingslashit( $cwd ); $cwd = trailingslashit( $cwd );
} }
return $cwd; return $cwd;
} }
@ -278,6 +288,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
// chmod any sub-objects if recursive. // chmod any sub-objects if recursive.
if ( $recursive && $this->is_dir( $file ) ) { if ( $recursive && $this->is_dir( $file ) ) {
$filelist = $this->dirlist( $file ); $filelist = $this->dirlist( $file );
foreach ( (array) $filelist as $filename => $filemeta ) { foreach ( (array) $filelist as $filename => $filemeta ) {
$this->chmod( $file . '/' . $filename, $mode, $recursive ); $this->chmod( $file . '/' . $filename, $mode, $recursive );
} }
@ -297,6 +308,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
*/ */
public function owner( $file ) { public function owner( $file ) {
$dir = $this->dirlist( $file ); $dir = $this->dirlist( $file );
return $dir[ $file ]['owner']; return $dir[ $file ]['owner'];
} }
@ -310,6 +322,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
*/ */
public function getchmod( $file ) { public function getchmod( $file ) {
$dir = $this->dirlist( $file ); $dir = $this->dirlist( $file );
return $dir[ $file ]['permsn']; return $dir[ $file ]['permsn'];
} }
@ -323,6 +336,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
*/ */
public function group( $file ) { public function group( $file ) {
$dir = $this->dirlist( $file ); $dir = $this->dirlist( $file );
return $dir[ $file ]['group']; return $dir[ $file ]['group'];
} }
@ -345,6 +359,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
} }
$content = $this->get_contents( $source ); $content = $this->get_contents( $source );
if ( false === $content ) { if ( false === $content ) {
return false; return false;
} }
@ -383,9 +398,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( empty( $file ) ) { if ( empty( $file ) ) {
return false; return false;
} }
if ( 'f' === $type || $this->is_file( $file ) ) { if ( 'f' === $type || $this->is_file( $file ) ) {
return $this->ftp->delete( $file ); return $this->ftp->delete( $file );
} }
if ( ! $recursive ) { if ( ! $recursive ) {
return $this->ftp->rmdir( $file ); return $this->ftp->rmdir( $file );
} }
@ -424,9 +441,11 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( $this->is_dir( $file ) ) { if ( $this->is_dir( $file ) ) {
return false; return false;
} }
if ( $this->exists( $file ) ) { if ( $this->exists( $file ) ) {
return true; return true;
} }
return false; return false;
} }
@ -440,10 +459,12 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
*/ */
public function is_dir( $path ) { public function is_dir( $path ) {
$cwd = $this->cwd(); $cwd = $this->cwd();
if ( $this->chdir( $path ) ) { if ( $this->chdir( $path ) ) {
$this->chdir( $cwd ); $this->chdir( $cwd );
return true; return true;
} }
return false; return false;
} }
@ -541,6 +562,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
*/ */
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path ); $path = untrailingslashit( $path );
if ( empty( $path ) ) { if ( empty( $path ) ) {
return false; return false;
} }
@ -548,10 +570,13 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( ! $this->ftp->mkdir( $path ) ) { if ( ! $this->ftp->mkdir( $path ) ) {
return false; return false;
} }
if ( ! $chmod ) { if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR; $chmod = FS_CHMOD_DIR;
} }
$this->chmod( $path, $chmod ); $this->chmod( $path, $chmod );
return true; return true;
} }
@ -605,6 +630,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
mbstring_binary_safe_encoding(); mbstring_binary_safe_encoding();
$list = $this->ftp->dirlist( $path ); $list = $this->ftp->dirlist( $path );
if ( empty( $list ) && ! $this->exists( $path ) ) { if ( empty( $list ) && ! $this->exists( $path ) ) {
reset_mbstring_encoding(); reset_mbstring_encoding();
@ -613,6 +639,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
} }
$ret = array(); $ret = array();
foreach ( $list as $struc ) { foreach ( $list as $struc ) {
if ( '.' === $struc['name'] || '..' === $struc['name'] ) { if ( '.' === $struc['name'] || '..' === $struc['name'] ) {

View File

@ -132,6 +132,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$this->options['hostname'] . ':' . $this->options['port'] $this->options['hostname'] . ':' . $this->options['port']
) )
); );
return false; return false;
} }
@ -145,6 +146,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$this->options['username'] $this->options['username']
) )
); );
return false; return false;
} }
} else { } else {
@ -157,11 +159,13 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$this->options['username'] $this->options['username']
) )
); );
return false; return false;
} }
} }
$this->sftp_link = ssh2_sftp( $this->link ); $this->sftp_link = ssh2_sftp( $this->link );
if ( ! $this->sftp_link ) { if ( ! $this->sftp_link ) {
$this->errors->add( $this->errors->add(
'connect', 'connect',
@ -171,6 +175,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$this->options['hostname'] . ':' . $this->options['port'] $this->options['hostname'] . ':' . $this->options['port']
) )
); );
return false; return false;
} }
@ -194,6 +199,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( '/' === $path ) { if ( '/' === $path ) {
$path = '/./'; $path = '/./';
} }
return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' ); return 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $path, '/' );
} }
@ -211,6 +217,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
} }
$stream = ssh2_exec( $this->link, $command ); $stream = ssh2_exec( $this->link, $command );
if ( ! $stream ) { if ( ! $stream ) {
$this->errors->add( $this->errors->add(
'command', 'command',
@ -232,6 +239,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
return $data; return $data;
} }
} }
return false; return false;
} }
@ -292,9 +300,11 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
*/ */
public function cwd() { public function cwd() {
$cwd = ssh2_sftp_realpath( $this->sftp_link, '.' ); $cwd = ssh2_sftp_realpath( $this->sftp_link, '.' );
if ( $cwd ) { if ( $cwd ) {
$cwd = trailingslashit( trim( $cwd ) ); $cwd = trailingslashit( trim( $cwd ) );
} }
return $cwd; return $cwd;
} }
@ -325,9 +335,11 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( ! $this->exists( $file ) ) { if ( ! $this->exists( $file ) ) {
return false; return false;
} }
if ( ! $recursive || ! $this->is_dir( $file ) ) { if ( ! $recursive || ! $this->is_dir( $file ) ) {
return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); return $this->run_command( sprintf( 'chgrp %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
} }
return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true ); return $this->run_command( sprintf( 'chgrp -R %s %s', escapeshellarg( $group ), escapeshellarg( $file ) ), true );
} }
@ -361,6 +373,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( ! $recursive || ! $this->is_dir( $file ) ) { if ( ! $recursive || ! $this->is_dir( $file ) ) {
return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true ); return $this->run_command( sprintf( 'chmod %o %s', $mode, escapeshellarg( $file ) ), true );
} }
return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true ); return $this->run_command( sprintf( 'chmod -R %o %s', $mode, escapeshellarg( $file ) ), true );
} }
@ -379,9 +392,11 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( ! $this->exists( $file ) ) { if ( ! $this->exists( $file ) ) {
return false; return false;
} }
if ( ! $recursive || ! $this->is_dir( $file ) ) { if ( ! $recursive || ! $this->is_dir( $file ) ) {
return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); return $this->run_command( sprintf( 'chown %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
} }
return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true ); return $this->run_command( sprintf( 'chown -R %s %s', escapeshellarg( $owner ), escapeshellarg( $file ) ), true );
} }
@ -395,16 +410,21 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
*/ */
public function owner( $file ) { public function owner( $file ) {
$owneruid = @fileowner( $this->sftp_path( $file ) ); $owneruid = @fileowner( $this->sftp_path( $file ) );
if ( ! $owneruid ) { if ( ! $owneruid ) {
return false; return false;
} }
if ( ! function_exists( 'posix_getpwuid' ) ) { if ( ! function_exists( 'posix_getpwuid' ) ) {
return $owneruid; return $owneruid;
} }
$ownerarray = posix_getpwuid( $owneruid ); $ownerarray = posix_getpwuid( $owneruid );
if ( ! $ownerarray ) { if ( ! $ownerarray ) {
return false; return false;
} }
return $ownerarray['name']; return $ownerarray['name'];
} }
@ -430,16 +450,21 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
*/ */
public function group( $file ) { public function group( $file ) {
$gid = @filegroup( $this->sftp_path( $file ) ); $gid = @filegroup( $this->sftp_path( $file ) );
if ( ! $gid ) { if ( ! $gid ) {
return false; return false;
} }
if ( ! function_exists( 'posix_getgrgid' ) ) { if ( ! function_exists( 'posix_getgrgid' ) ) {
return $gid; return $gid;
} }
$grouparray = posix_getgrgid( $gid ); $grouparray = posix_getgrgid( $gid );
if ( ! $grouparray ) { if ( ! $grouparray ) {
return false; return false;
} }
return $grouparray['name']; return $grouparray['name'];
} }
@ -460,10 +485,13 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( ! $overwrite && $this->exists( $destination ) ) { if ( ! $overwrite && $this->exists( $destination ) ) {
return false; return false;
} }
$content = $this->get_contents( $source ); $content = $this->get_contents( $source );
if ( false === $content ) { if ( false === $content ) {
return false; return false;
} }
return $this->put_contents( $destination, $content, $mode ); return $this->put_contents( $destination, $content, $mode );
} }
@ -508,15 +536,19 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( 'f' === $type || $this->is_file( $file ) ) { if ( 'f' === $type || $this->is_file( $file ) ) {
return ssh2_sftp_unlink( $this->sftp_link, $file ); return ssh2_sftp_unlink( $this->sftp_link, $file );
} }
if ( ! $recursive ) { if ( ! $recursive ) {
return ssh2_sftp_rmdir( $this->sftp_link, $file ); return ssh2_sftp_rmdir( $this->sftp_link, $file );
} }
$filelist = $this->dirlist( $file ); $filelist = $this->dirlist( $file );
if ( is_array( $filelist ) ) { if ( is_array( $filelist ) ) {
foreach ( $filelist as $filename => $fileinfo ) { foreach ( $filelist as $filename => $fileinfo ) {
$this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] ); $this->delete( $file . '/' . $filename, $recursive, $fileinfo['type'] );
} }
} }
return ssh2_sftp_rmdir( $this->sftp_link, $file ); return ssh2_sftp_rmdir( $this->sftp_link, $file );
} }
@ -650,6 +682,7 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
*/ */
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) { public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
$path = untrailingslashit( $path ); $path = untrailingslashit( $path );
if ( empty( $path ) ) { if ( empty( $path ) ) {
return false; return false;
} }
@ -657,15 +690,19 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
if ( ! $chmod ) { if ( ! $chmod ) {
$chmod = FS_CHMOD_DIR; $chmod = FS_CHMOD_DIR;
} }
if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) { if ( ! ssh2_sftp_mkdir( $this->sftp_link, $path, $chmod, true ) ) {
return false; return false;
} }
if ( $chown ) { if ( $chown ) {
$this->chown( $path, $chown ); $this->chown( $path, $chown );
} }
if ( $chgrp ) { if ( $chgrp ) {
$this->chgrp( $path, $chgrp ); $this->chgrp( $path, $chgrp );
} }
return true; return true;
} }
@ -764,8 +801,10 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
$ret[ $struc['name'] ] = $struc; $ret[ $struc['name'] ] = $struc;
} }
$dir->close(); $dir->close();
unset( $dir ); unset( $dir );
return $ret; return $ret;
} }
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-48088'; $wp_version = '5.5-alpha-48089';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.