mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@48089 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -64,6 +64,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
*/
|
||||
public function put_contents( $file, $contents, $mode = false ) {
|
||||
$fp = @fopen( $file, 'wb' );
|
||||
|
||||
if ( ! $fp ) {
|
||||
return false;
|
||||
}
|
||||
@@ -125,15 +126,19 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
if ( ! $this->exists( $file ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $recursive ) {
|
||||
return chgrp( $file, $group );
|
||||
}
|
||||
|
||||
if ( ! $this->is_dir( $file ) ) {
|
||||
return chgrp( $file, $group );
|
||||
}
|
||||
|
||||
// Is a directory, and we want recursive.
|
||||
$file = trailingslashit( $file );
|
||||
$filelist = $this->dirlist( $file );
|
||||
|
||||
foreach ( $filelist as $filename ) {
|
||||
$this->chgrp( $file . $filename, $group, $recursive );
|
||||
}
|
||||
@@ -167,9 +172,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
if ( ! $recursive || ! $this->is_dir( $file ) ) {
|
||||
return chmod( $file, $mode );
|
||||
}
|
||||
|
||||
// Is a directory, and we want recursive.
|
||||
$file = trailingslashit( $file );
|
||||
$filelist = $this->dirlist( $file );
|
||||
|
||||
foreach ( (array) $filelist as $filename => $filemeta ) {
|
||||
$this->chmod( $file . $filename, $mode, $recursive );
|
||||
}
|
||||
@@ -192,17 +199,22 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
if ( ! $this->exists( $file ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $recursive ) {
|
||||
return chown( $file, $owner );
|
||||
}
|
||||
|
||||
if ( ! $this->is_dir( $file ) ) {
|
||||
return chown( $file, $owner );
|
||||
}
|
||||
|
||||
// Is a directory, and we want recursive.
|
||||
$filelist = $this->dirlist( $file );
|
||||
|
||||
foreach ( $filelist as $filename ) {
|
||||
$this->chown( $file . '/' . $filename, $owner, $recursive );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -216,16 +228,21 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
*/
|
||||
public function owner( $file ) {
|
||||
$owneruid = @fileowner( $file );
|
||||
|
||||
if ( ! $owneruid ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'posix_getpwuid' ) ) {
|
||||
return $owneruid;
|
||||
}
|
||||
|
||||
$ownerarray = posix_getpwuid( $owneruid );
|
||||
|
||||
if ( ! $ownerarray ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $ownerarray['name'];
|
||||
}
|
||||
|
||||
@@ -253,16 +270,21 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
*/
|
||||
public function group( $file ) {
|
||||
$gid = @filegroup( $file );
|
||||
|
||||
if ( ! $gid ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'posix_getgrgid' ) ) {
|
||||
return $gid;
|
||||
}
|
||||
|
||||
$grouparray = posix_getgrgid( $gid );
|
||||
|
||||
if ( ! $grouparray ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $grouparray['name'];
|
||||
}
|
||||
|
||||
@@ -285,9 +307,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
}
|
||||
|
||||
$rtval = copy( $source, $destination );
|
||||
|
||||
if ( $mode ) {
|
||||
$this->chmod( $destination, $mode );
|
||||
}
|
||||
|
||||
return $rtval;
|
||||
}
|
||||
|
||||
@@ -314,6 +338,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
|
||||
if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) {
|
||||
$this->delete( $source );
|
||||
|
||||
return true;
|
||||
} else {
|
||||
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.
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = str_replace( '\\', '/', $file ); // For Win32, occasional problems deleting files otherwise.
|
||||
|
||||
if ( 'f' === $type || $this->is_file( $file ) ) {
|
||||
return @unlink( $file );
|
||||
}
|
||||
|
||||
if ( ! $recursive && $this->is_dir( $file ) ) {
|
||||
return @rmdir( $file );
|
||||
}
|
||||
@@ -351,6 +378,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
$filelist = $this->dirlist( $file, true );
|
||||
|
||||
$retval = true;
|
||||
|
||||
if ( is_array( $filelist ) ) {
|
||||
foreach ( $filelist as $filename => $fileinfo ) {
|
||||
if ( ! $this->delete( $file . $filename, $recursive, $fileinfo['type'] ) ) {
|
||||
@@ -480,9 +508,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
if ( 0 == $time ) {
|
||||
$time = time();
|
||||
}
|
||||
|
||||
if ( 0 == $atime ) {
|
||||
$atime = time();
|
||||
}
|
||||
|
||||
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 ) {
|
||||
// Safe mode fails with a trailing slash under certain PHP versions.
|
||||
$path = untrailingslashit( $path );
|
||||
|
||||
if ( empty( $path ) ) {
|
||||
return false;
|
||||
}
|
||||
@@ -514,13 +545,17 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
if ( ! @mkdir( $path ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->chmod( $path, $chmod );
|
||||
|
||||
if ( $chown ) {
|
||||
$this->chown( $path, $chown );
|
||||
}
|
||||
|
||||
if ( $chgrp ) {
|
||||
$this->chgrp( $path, $chgrp );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -576,6 +611,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
}
|
||||
|
||||
$dir = dir( $path );
|
||||
|
||||
if ( ! $dir ) {
|
||||
return false;
|
||||
}
|
||||
@@ -619,8 +655,10 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
|
||||
$ret[ $struc['name'] ] = $struc;
|
||||
}
|
||||
|
||||
$dir->close();
|
||||
unset( $dir );
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user