diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/class-wp-filesystem-direct.php --- a/wp/wp-admin/includes/class-wp-filesystem-direct.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-filesystem-direct.php Tue Dec 15 13:49:49 2020 +0100 @@ -64,6 +64,7 @@ */ public function put_contents( $file, $contents, $mode = false ) { $fp = @fopen( $file, 'wb' ); + if ( ! $fp ) { return false; } @@ -95,7 +96,7 @@ * @return string|false The current working directory on success, false on failure. */ public function cwd() { - return @getcwd(); + return getcwd(); } /** @@ -125,15 +126,19 @@ if ( ! $this->exists( $file ) ) { return false; } + if ( ! $recursive ) { - return @chgrp( $file, $group ); + return chgrp( $file, $group ); } + 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 ); $filelist = $this->dirlist( $file ); + foreach ( $filelist as $filename ) { $this->chgrp( $file . $filename, $group, $recursive ); } @@ -149,7 +154,7 @@ * @param string $file Path to the file. * @param int|false $mode Optional. The permissions as octal number, usually 0644 for files, * 0755 for directories. Default false. - * @param bool $recursive Optional. If set to true, changes file group recursively. + * @param bool $recursive Optional. If set to true, changes file permissions recursively. * Default false. * @return bool True on success, false on failure. */ @@ -165,11 +170,13 @@ } 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 ); $filelist = $this->dirlist( $file ); + foreach ( (array) $filelist as $filename => $filemeta ) { $this->chmod( $file . $filename, $mode, $recursive ); } @@ -192,17 +199,22 @@ if ( ! $this->exists( $file ) ) { return false; } + if ( ! $recursive ) { - return @chown( $file, $owner ); + return chown( $file, $owner ); } + 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 ); + foreach ( $filelist as $filename ) { $this->chown( $file . '/' . $filename, $owner, $recursive ); } + return true; } @@ -216,13 +228,21 @@ */ 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']; } @@ -250,13 +270,21 @@ */ 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']; } @@ -279,9 +307,11 @@ } $rtval = copy( $source, $destination ); + if ( $mode ) { $this->chmod( $destination, $mode ); } + return $rtval; } @@ -308,6 +338,7 @@ if ( $this->copy( $source, $destination, $overwrite ) && $this->exists( $destination ) ) { $this->delete( $source ); + return true; } else { return false; @@ -320,30 +351,34 @@ * @since 2.5.0 * * @param string $file Path to the file or directory. - * @param bool $recursive Optional. If set to true, changes file group recursively. + * @param bool $recursive Optional. If set to true, deletes files and folders recursively. * Default false. * @param string|false $type Type of resource. 'f' for file, 'd' for directory. * Default false. * @return bool True on success, false on failure. */ public function delete( $file, $recursive = false, $type = false ) { - if ( empty( $file ) ) { // Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. + if ( empty( $file ) ) { + // 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 ) ) { + $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 ); } - // At this point it's a folder, and we're in recursive mode + // At this point it's a folder, and we're in recursive mode. $file = trailingslashit( $file ); $filelist = $this->dirlist( $file, true ); $retval = true; + if ( is_array( $filelist ) ) { foreach ( $filelist as $filename => $fileinfo ) { if ( ! $this->delete( $file . $filename, $recursive, $fileinfo['type'] ) ) { @@ -470,13 +505,15 @@ * @return bool True on success, false on failure. */ public function touch( $file, $time = 0, $atime = 0 ) { - if ( $time == 0 ) { + if ( 0 == $time ) { $time = time(); } - if ( $atime == 0 ) { + + if ( 0 == $atime ) { $atime = time(); } - return @touch( $file, $time, $atime ); + + return touch( $file, $time, $atime ); } /** @@ -496,6 +533,7 @@ 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; } @@ -507,13 +545,17 @@ if ( ! @mkdir( $path ) ) { return false; } + $this->chmod( $path, $chmod ); + if ( $chown ) { $this->chown( $path, $chown ); } + if ( $chgrp ) { $this->chgrp( $path, $chgrp ); } + return true; } @@ -564,11 +606,12 @@ $limit_file = false; } - if ( ! $this->is_dir( $path ) ) { + if ( ! $this->is_dir( $path ) || ! $this->is_readable( $path ) ) { return false; } - $dir = @dir( $path ); + $dir = dir( $path ); + if ( ! $dir ) { return false; } @@ -579,11 +622,11 @@ $struc = array(); $struc['name'] = $entry; - if ( '.' == $struc['name'] || '..' == $struc['name'] ) { + if ( '.' === $struc['name'] || '..' === $struc['name'] ) { continue; } - if ( ! $include_hidden && '.' == $struc['name'][0] ) { + if ( ! $include_hidden && '.' === $struc['name'][0] ) { continue; } @@ -598,11 +641,11 @@ $struc['group'] = $this->group( $path . '/' . $entry ); $struc['size'] = $this->size( $path . '/' . $entry ); $struc['lastmodunix'] = $this->mtime( $path . '/' . $entry ); - $struc['lastmod'] = date( 'M j', $struc['lastmodunix'] ); - $struc['time'] = date( 'h:i:s', $struc['lastmodunix'] ); + $struc['lastmod'] = gmdate( 'M j', $struc['lastmodunix'] ); + $struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] ); $struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f'; - if ( 'd' == $struc['type'] ) { + if ( 'd' === $struc['type'] ) { if ( $recursive ) { $struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive ); } else { @@ -612,8 +655,10 @@ $ret[ $struc['name'] ] = $struc; } + $dir->close(); unset( $dir ); + return $ret; } }