diff --git a/inc/Core/FilesRepository/FilesystemHelper.php b/inc/Core/FilesRepository/FilesystemHelper.php index 5764b7ce6e..d9532e0576 100644 --- a/inc/Core/FilesRepository/FilesystemHelper.php +++ b/inc/Core/FilesRepository/FilesystemHelper.php @@ -106,6 +106,10 @@ public static function get(): ?\WP_Filesystem_Base { * @return bool True if the file is (or was made) group-writable, false otherwise. */ public static function make_group_writable( string $filepath, int $permissions = self::AGENT_FILE_PERMISSIONS ): bool { + // Atomic replacement or another process may have changed the inode or mode. + // Permission and ownership decisions must describe the current file. + clearstatcache( true, $filepath ); + if ( ! file_exists( $filepath ) ) { return false; } @@ -127,7 +131,10 @@ public static function make_group_writable( string $filepath, int $permissions = // Suppress any residual warning — a failed chmod is non-fatal here. // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_chmod, WordPress.PHP.NoSilencedErrors.Discouraged - return @chmod( $filepath, $permissions ); + $result = @chmod( $filepath, $permissions ); + // PHP 8.2 can retain the pre-chmod mode for subsequent stat calls. + clearstatcache( true, $filepath ); + return $result; } /** diff --git a/tests/Unit/Abilities/Media/StackTemplateTest.php b/tests/Unit/Abilities/Media/StackTemplateTest.php index 20fd9e35e9..7c853459e2 100644 --- a/tests/Unit/Abilities/Media/StackTemplateTest.php +++ b/tests/Unit/Abilities/Media/StackTemplateTest.php @@ -178,6 +178,11 @@ public function test_list_item_colors_render_without_leaking_to_other_items(): v ); $paths = \DataMachine\Abilities\Media\BrandTokens::with_overrides( $data['brand'], static fn() => $t->render( $data, $r ) ); $this->files = array_merge( $this->files, $paths ); + foreach ( array( 'body', 'heading' ) as $font ) { + if ( ! is_readable( $r->get_font( $font ) ) ) { + $this->markTestSkipped( 'Readable body and heading fonts required for pixel assertions.' ); + } + } $box = $t->plan_layout( $r, $data )[0]; $line = (int) ( 64 * 1.2 ); foreach ( array( 0 => 0xffffff, 1 => 0xff0000, 2 => 0xffffff ) as $i => $expected ) { diff --git a/tests/filesystem-permission-cache-smoke.php b/tests/filesystem-permission-cache-smoke.php new file mode 100644 index 0000000000..d2c8966a60 --- /dev/null +++ b/tests/filesystem-permission-cache-smoke.php @@ -0,0 +1,48 @@ +