Skip to content

Commit f153af3

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents 56334b4 + 227acbc commit f153af3

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function chmod( $file, $mode = false, $recursive = false ) {
176176
}
177177

178178
if ( ! $recursive || ! $this->is_dir( $file ) ) {
179-
$current_mode = fileperms( $file ) & 0777 | 0644;
179+
$current_mode = fileperms( $file ) & 0777;
180180

181181
/*
182182
* fileperms() populates the stat cache, so have to clear it

‎tests/phpunit/tests/filesystem/wpFilesystemDirect/chmod.php‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,36 @@ public function test_should_change_mode_recursively(): void {
101101
'The mode was not applied to a file in a nested subdirectory.'
102102
);
103103
}
104+
105+
/**
106+
* Tests that `WP_Filesystem_Direct::chmod()` uses the correct mask for comparing permissions.
107+
*
108+
* The `& 0777` mask should be used to strip the filetype bits from the `fileperms( $file )` value
109+
* so that the current permission bits can be used for comparison with the requested mode.
110+
*
111+
* @ticket 65695
112+
*/
113+
public function test_should_use_correct_permission_mask_for_files(): void {
114+
if ( self::is_windows() ) {
115+
$this->markTestSkipped( 'chmod() does not support octal modes on Windows.' );
116+
}
117+
118+
$file = self::$file_structure['visible_file']['path'];
119+
120+
// Set the initial permissions.
121+
self::$filesystem->chmod( $file, 0600 );
122+
123+
$this->assertTrue(
124+
self::$filesystem->chmod( $file, 0644 ),
125+
'chmod() did not report success.'
126+
);
127+
128+
clearstatcache();
129+
130+
$this->assertSame(
131+
'644',
132+
self::$filesystem->getchmod( $file ),
133+
'The requested mode was not applied to the file.'
134+
);
135+
}
104136
}

0 commit comments

Comments
 (0)