From fc52d9cbb1a9a19bff47b64cdb4bdb11bdc845a9 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 24 Jun 2015 04:48:18 +0000 Subject: [PATCH] WP Filesystem: Correctly parse the permissions field in the directory listings, and actually set it in FTP environments Props mnelson4 for initial patch. Fixes #29548 git-svn-id: https://develop.svn.wordpress.org/trunk@32923 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-filesystem-base.php | 13 ++++++++++++- .../includes/class-wp-filesystem-ftpext.php | 3 ++- .../includes/class-wp-filesystem-ftpsockets.php | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wp-admin/includes/class-wp-filesystem-base.php b/src/wp-admin/includes/class-wp-filesystem-base.php index c8b8a54f68..3b43227160 100644 --- a/src/wp-admin/includes/class-wp-filesystem-base.php +++ b/src/wp-admin/includes/class-wp-filesystem-base.php @@ -310,7 +310,7 @@ class WP_Filesystem_Base { * @return string The *nix-style representation of permissions. */ public function gethchmod( $file ){ - $perms = $this->getchmod($file); + $perms = intval( $this->getchmod( $file ), 8 ); if (($perms & 0xC000) == 0xC000) // Socket $info = 's'; elseif (($perms & 0xA000) == 0xA000) // Symbolic Link @@ -351,6 +351,17 @@ class WP_Filesystem_Base { return $info; } + /** + * Gets the permissions of the specified file or filepath in their octal format + * + * @since 4.0 + * @param string $file + * @return string the last 3 characters of the octal number + */ + public function getchmod( $file ) { + return '777'; + } + /** * Convert *nix-style file permissions to a octal number. * diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpext.php b/src/wp-admin/includes/class-wp-filesystem-ftpext.php index d58da3aec7..62ade49136 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -384,7 +384,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { /** * @staticvar bool $is_windows * @param string $line - * @return string + * @return array */ public function parselisting($line) { static $is_windows = null; @@ -426,6 +426,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { else $b['type'] = 'f'; $b['perms'] = $lucifer[0]; + $b['permsn'] = $this->getnumchmodfromh( $b['perms'] ); $b['number'] = $lucifer[1]; $b['owner'] = $lucifer[2]; $b['group'] = $lucifer[3]; diff --git a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php index a0acdebf39..879a2e8ca8 100644 --- a/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/src/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -449,6 +449,9 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { if ( $struc['islink'] ) $struc['name'] = preg_replace( '/(\s*->\s*.*)$/', '', $struc['name'] ); + // Add the Octal representation of the file permissions + $struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] ); + $ret[ $struc['name'] ] = $struc; }