Skip to content

Commit 600dbef

Browse files
committed
Filesystem API: Resolve FIXME comment for WP_Filesystem_Direct::getchmod() by explicitly returning '0' in error case.
Developed in #10637 Follow-up to [11831]. Props vietcgi, westonruter. See #10304. Fixes #64426. git-svn-id: https://develop.svn.wordpress.org/trunk@61398 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c4d8047 commit 600dbef

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/wp-admin/includes/class-wp-filesystem-direct.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,18 @@ public function owner( $file ) {
249249
/**
250250
* Gets the permissions of the specified file or filepath in their octal format.
251251
*
252-
* FIXME does not handle errors in fileperms()
253-
*
254252
* @since 2.5.0
255253
*
256254
* @param string $file Path to the file.
257-
* @return string Mode of the file (the last 3 digits).
255+
* @return string Mode of the file (the last 3 digits), or the string "0" on failure.
258256
*/
259257
public function getchmod( $file ) {
260-
return substr( decoct( @fileperms( $file ) ), -3 );
258+
$perms = @fileperms( $file );
259+
if ( false === $perms ) {
260+
return '0';
261+
}
262+
263+
return substr( decoct( $perms ), -3 );
261264
}
262265

263266
/**

tests/phpunit/tests/filesystem/wpFilesystemDirect/getchmod.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ public function test_should_get_chmod_for_a_path_that_exists( $path ) {
3333

3434
/**
3535
* Tests that `WP_Filesystem_Direct::getchmod()` returns
36-
* the permissions for a path that does not exist.
36+
* "0" for a path that does not exist.
3737
*
3838
* @dataProvider data_paths_that_do_not_exist
3939
*
4040
* @ticket 57774
41+
* @ticket 64426
4142
*
4243
* @param string $path The path.
4344
*/
44-
public function test_should_get_chmod_for_a_path_that_does_not_exist( $path ) {
45+
public function test_should_return_zero_for_a_path_that_does_not_exist( $path ) {
4546
$actual = self::$filesystem->getchmod( self::$file_structure['test_dir']['path'] . $path );
46-
$this->assertNotSame( '', $actual );
47+
$this->assertSame( '0', $actual );
4748
}
4849
}

0 commit comments

Comments
 (0)