From f538cda53f049d9eb6ef4f75088b9210a9f70958 Mon Sep 17 00:00:00 2001 From: acoulton Date: Fri, 10 May 2024 09:52:29 +0100 Subject: [PATCH] [Filesystem] Fix dumpFile `stat failed` error hitting custom handler Since #54471, dumpFile will trigger a `fileperms(): stat failed` error when writing to a filename that does not yet exist. This was silenced from PHP's default handler with the `@` operator. However, the error is still passed to any custom handler that the application has registered, and can therefore cause exceptions or spurious logging depending on the implementation of the handler. The better solution, which is consistent with all other calls to native functions in this class, would be to use `self::box` to catch and ignore the potential error so that it never leaks outside this class. --- Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Filesystem.php b/Filesystem.php index c5cfa4714..700311d58 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -691,7 +691,7 @@ public function dumpFile(string $filename, $content) throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename); } - self::box('chmod', $tmpFile, @fileperms($filename) ?: 0666 & ~umask()); + self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0666 & ~umask()); $this->rename($tmpFile, $filename, true); } finally {