Make WordPress Core

Changeset 61601


Ignore:
Timestamp:
02/09/2026 04:53:07 PM (7 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-filesystem-direct.php

    r61398 r61601  
    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                }
Note: See TracChangeset for help on using the changeset viewer.