Skip to content

Commit 247182a

Browse files
committed
[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.
1 parent fbc47bc commit 247182a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Symfony/Component/Filesystem/Filesystem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ public function dumpFile(string $filename, $content)
691691
throw new IOException(sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename);
692692
}
693693

694-
self::box('chmod', $tmpFile, @fileperms($filename) ?: 0666 & ~umask());
694+
self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0666 & ~umask());
695695

696696
$this->rename($tmpFile, $filename, true);
697697
} finally {

0 commit comments

Comments
 (0)