Filesystem API: Use trailingslashit( $path ) instead of $path . '/'. Fixes a warning when $path already ends with a slash.

Props: costdev, afragen, mukesh27.
Fixes: #57516.

git-svn-id: https://develop.svn.wordpress.org/trunk@55354 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2023-02-16 22:11:32 +00:00
parent 5a87725ed9
commit 1ad7735355
4 changed files with 24 additions and 19 deletions

View File

@@ -629,7 +629,8 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
return false;
}
$ret = array();
$path = trailingslashit( $path );
$ret = array();
while ( false !== ( $entry = $dir->read() ) ) {
$struc = array();
@@ -647,20 +648,20 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
continue;
}
$struc['perms'] = $this->gethchmod( $path . '/' . $entry );
$struc['perms'] = $this->gethchmod( $path . $entry );
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] );
$struc['number'] = false;
$struc['owner'] = $this->owner( $path . '/' . $entry );
$struc['group'] = $this->group( $path . '/' . $entry );
$struc['size'] = $this->size( $path . '/' . $entry );
$struc['lastmodunix'] = $this->mtime( $path . '/' . $entry );
$struc['owner'] = $this->owner( $path . $entry );
$struc['group'] = $this->group( $path . $entry );
$struc['size'] = $this->size( $path . $entry );
$struc['lastmodunix'] = $this->mtime( $path . $entry );
$struc['lastmod'] = gmdate( 'M j', $struc['lastmodunix'] );
$struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] );
$struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
$struc['type'] = $this->is_dir( $path . $entry ) ? 'd' : 'f';
if ( 'd' === $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
$struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}

View File

@@ -761,12 +761,13 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base {
$dirlist[ $entry['name'] ] = $entry;
}
$ret = array();
$path = trailingslashit( $path );
$ret = array();
foreach ( (array) $dirlist as $struc ) {
if ( 'd' === $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
$struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}

View File

@@ -645,7 +645,8 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
return false;
}
$ret = array();
$path = trailingslashit( $path );
$ret = array();
foreach ( $list as $struc ) {
@@ -663,7 +664,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base {
if ( 'd' === $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
$struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}

View File

@@ -774,6 +774,8 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
return false;
}
$path = trailingslashit( $path );
while ( false !== ( $entry = $dir->read() ) ) {
$struc = array();
$struc['name'] = $entry;
@@ -790,20 +792,20 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base {
continue;
}
$struc['perms'] = $this->gethchmod( $path . '/' . $entry );
$struc['perms'] = $this->gethchmod( $path . $entry );
$struc['permsn'] = $this->getnumchmodfromh( $struc['perms'] );
$struc['number'] = false;
$struc['owner'] = $this->owner( $path . '/' . $entry );
$struc['group'] = $this->group( $path . '/' . $entry );
$struc['size'] = $this->size( $path . '/' . $entry );
$struc['lastmodunix'] = $this->mtime( $path . '/' . $entry );
$struc['owner'] = $this->owner( $path . $entry );
$struc['group'] = $this->group( $path . $entry );
$struc['size'] = $this->size( $path . $entry );
$struc['lastmodunix'] = $this->mtime( $path . $entry );
$struc['lastmod'] = gmdate( 'M j', $struc['lastmodunix'] );
$struc['time'] = gmdate( 'h:i:s', $struc['lastmodunix'] );
$struc['type'] = $this->is_dir( $path . '/' . $entry ) ? 'd' : 'f';
$struc['type'] = $this->is_dir( $path . $entry ) ? 'd' : 'f';
if ( 'd' === $struc['type'] ) {
if ( $recursive ) {
$struc['files'] = $this->dirlist( $path . '/' . $struc['name'], $include_hidden, $recursive );
$struc['files'] = $this->dirlist( $path . $struc['name'], $include_hidden, $recursive );
} else {
$struc['files'] = array();
}