Commit 19f84cb43f for wordpress.org
commit 19f84cb43f707ed7813f04609f4d032d49991826
Author: Sergey Biryukov <sergeybiryukov.ru@gmail.com>
Date: Mon Feb 9 16:54:42 2026 +0000
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.
Built from https://develop.svn.wordpress.org/trunk@61601
git-svn-id: http://core.svn.wordpress.org/trunk@60912 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php
index ed22a821a1..a4b197c152 100644
--- a/wp-admin/includes/class-wp-filesystem-direct.php
+++ b/wp-admin/includes/class-wp-filesystem-direct.php
@@ -170,6 +170,22 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
}
if ( ! $recursive || ! $this->is_dir( $file ) ) {
+ $current_mode = fileperms( $file ) & 0777 | 0644;
+
+ /*
+ * fileperms() populates the stat cache, so have to clear it
+ * to maintain parity with the previous behavior.
+ */
+ clearstatcache( true, $file );
+
+ /*
+ * Avoid calling chmod() if the requested mode is already set,
+ * to prevent throwing a warning when we aren't the owner.
+ */
+ if ( $current_mode === $mode ) {
+ return true;
+ }
+
return chmod( $file, $mode );
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 1d1d637b79..a3ed90a601 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.0-alpha-61600';
+$wp_version = '7.0-alpha-61601';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.