Skip to content

Commit edbdcbe

Browse files
Filesystem API: Avoid chmod() warnings if the permissions already match.
This prevents spurious warnings from `WP_Filesystem_Direct::chmod()` when the web process doesn't have ownership over the files, and thus cannot change the permissions, even if only to reassert the existing mode. Follow-up to [6779], [11667], [12998]. Props redsweater, mukesh27, SergeyBiryukov. Fixes #64610. git-svn-id: https://develop.svn.wordpress.org/trunk@61601 602fd350-edb4-49c9-b593-d223f7449a82
1 parent bdfd433 commit edbdcbe

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ public function chmod( $file, $mode = false, $recursive = false ) {
170170
}
171171

172172
if ( ! $recursive || ! $this->is_dir( $file ) ) {
173+
$current_mode = fileperms( $file ) & 0777 | 0644;
174+
175+
/*
176+
* fileperms() populates the stat cache, so have to clear it
177+
* to maintain parity with the previous behavior.
178+
*/
179+
clearstatcache( true, $file );
180+
181+
/*
182+
* Avoid calling chmod() if the requested mode is already set,
183+
* to prevent throwing a warning when we aren't the owner.
184+
*/
185+
if ( $current_mode === $mode ) {
186+
return true;
187+
}
188+
173189
return chmod( $file, $mode );
174190
}
175191

0 commit comments

Comments
 (0)